CryptoSys PKI Toolkit Manual

HASH_HexFromHex

HASH_HexFromHex creates a message digest hash in hexadecimal format from data in a hexadecimal-encoded string. The hash algorithm to use is passed in the options parameter.

VB6/VBA Syntax

Public Declare Function HASH_HexFromHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal strMsgHex As String, ByVal nOptions As Long) As Long

nRet = HASH_HexFromHex(strOutput, nMaxChars, strMsgHex, nOptions)

Parameters

strOutput
[out] String to receive hash digest in hexadecimal format.
nMaxChars
[in] Long specifying the maximum number of characters to be received.
strMsgHex
[in] String containing the message data in hexadecimal-encoded format.
nOptions
[in] Long Option flags. Select one of:
PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
PKI_HASH_MD5 to use the MD5 algorithm
PKI_HASH_MD2 to use the MD2 algorithm
PKI_HASH_SHA256 to use the SHA-256 algorithm
PKI_HASH_SHA384 to use the SHA-384 algorithm
PKI_HASH_SHA512 to use the SHA-512 algorithm
PKI_HASH_SHA224 to use the SHA-224 algorithm

C/C++ Syntax

long _stdcall HASH_HexFromHex(char *szOutput, long nMaxChars, const char *szMsgHex, long nOptions);

Returns (VB6/C)

Long: If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.

.NET Equivalent

Hash.HexFromHex Method

Remarks

Specify a zero nOutChars or a NULL strOutput parameter to find out the required length of the output string, or use the appropriate PKI_xxx_CHARS constant. The maximum number of characters is PKI_MAX_HASH_CHARS. C/C++ users should add one to this value before allocating memory. The final digest will be truncated to the specified length if less than the expected size. Valid input hex digits are [0-9A-Fa-f]. The output is always in lower-case letters.

Example

Dim strDigest As String
Dim nRet As Long
Dim strData As String
' Compute SHA-1("abc")
strDigest = String(PKI_SHA1_CHARS, " ")
strData = "616263"
nRet = HASH_HexFromHex(strDigest, Len(strDigest), strData, PKI_HASH_SHA1)
Debug.Print strDigest
' Compute SHA-224("abc")
strDigest = String(PKI_SHA224_CHARS, " ")
strData = "616263"
nRet = HASH_HexFromHex(strDigest, Len(strDigest), strData, PKI_HASH_SHA224)
Debug.Print strDigest

This should produce the following output:

a9993e364706816aba3e25717850c26c9cd0d89d
23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7

See Also

HASH_HexFromBytes HASH_Bytes

[Contents] [Index]

[HOME]   [NEXT: HMAC_Bytes...]

Copyright © 2004-9 D.I. Management Services Pty Ltd. All rights reserved.