CryptoSys API examples VB6 to VB.NET

SHA1_AddString

Adds a string of ascii characters to the digest.

VB6/VBA

Debug.Print "Testing SHA1_AddString ..."
Dim nRet As Long
Dim strDigest As String
Dim hContext As Long

' Set context handle
hContext = SHA1_Init()

Debug.Print "SHA1_Init() returns handle = " & Hex(hContext)
' Remember to check for an invalid handle
If hContext = 0 Then
    MsgBox "Failed to set context"
    Exit Sub
End If

' Add strings one by one
nRet = SHA1_AddString(hContext, "a")
nRet = SHA1_AddString(hContext, "bc")

' Set strDigest to be 40 chars
strDigest = String(40, " ")
nRet = SHA1_HexDigest(strDigest, hContext)
Debug.Print strDigest

Output

Testing SHA1_AddString ...
SHA1_Init() returns handle = 15C96890
a9993e364706816aba3e25717850c26c9cd0d89d

VB.NET

Console.WriteLine("Testing SHA1_AddString ...")
''Dim nRet As Integer
Dim strDigest As String
''Dim hContext As Integer
Dim fIsOK As Boolean
Dim oSha1 As Sha1 = Sha1.Instance()

' Set context handle
fIsOK = oSha1.Init()

Console.WriteLine("SHA1_Init() returns handle = " & fIsOK)
' Remember to check for an invalid handle
If Not fIsOK Then
    MsgBox("Failed to set context")
    Exit Sub
End If

' Add strings one by one
oSha1.AddData("a")
oSha1.AddData("bc")

' Set strDigest to be 40 chars
''strDigest = String(40, " ")
strDigest = oSha1.HexDigest()
Console.WriteLine(strDigest)

[Contents]

[HOME]   [NEXT: SHA1_BytesHash...]

Copyright © 2009-20 D.I. Management Services Pty Ltd. All rights reserved.