CryptoSys API Library Manual

MD5_AddString

Adds a string of ascii characters to the digest.

VB6/VBA Syntax

Public Declare Function MD5_AddString Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strMessage As String) As Long

nRet = MD5_AddString(hContext, strMessage)

Parameters

hContext
[in] Long handle to the MD5 context.
strMessage
[in] String containing the next part of the message to be hashed.

C/C++ Syntax

long _stdcall MD5_AddString(long ctx_handle, const char *strMessage);

Returns (VB6/C)

Long: If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Md5.AddData Method (String)

Remarks

The handle to the context hContext must have been set up with a prior call to MD5_Init. This function may be called many times before creating the final message digest with MD5_HexDigest This function should only be used to hash "printable" strings. To hash a string that contains binary characters, such as ascii zero, use MD5_AddBytes.

Example

    Dim nRet As Long
    Dim strDigest As String
    Dim hContext As Long
    Dim i As Long
    Dim sA1000 As String

    ' Set context handle
    hContext = MD5_Init()
    If hContext = 0 Then
        MsgBox "Failed to set context"
        Exit Function
    End If

    ' Create a string of 1000 'a's
    sA1000 = String(1000, "a")

    ' Add 1000 times => one million repetitions of "a"
    For i = 1 To 1000
        nRet = MD5_AddString(hContext, sA1000)
    Next

    ' Set strDigest to be 32 chars - don't forget!!
    strDigest = String(32, " ")
    nRet = MD5_HexDigest(strDigest, hContext)
    Debug.Print strDigest

This should result in output as follows:

7707d6ae4e027c70eea2a935c2296f21

Note that the actual value of the handle is not important, just that it should not be zero.

See Also

MD5_Init MD5_AddBytes MD5_HexDigest MD5_Reset

[Contents] [Index]

[HOME]   [NEXT: MD5_BytesHash...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.