CryptoSys API Library Manual

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.

VBA/VB6 Syntax

Public Declare Function HASH_HexFromHex Lib "diCryptoSys.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)

C/C++ Syntax

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

Parameters

szOutput
[out] to receive hash digest in hexadecimal format.
nMaxChars
[in] specifying the maximum number of characters to be received.
szMsgHex
[in] containing the message data in hexadecimal-encoded format.
nOptions
[in] Option flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
API_HASH_ASCON_HASH to use the ASCON-HASH algorithm
API_HASH_ASCON_HASHA to use the ASCON-HASHA algorithm

Returns (VBA/C)

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

VBA Wrapper Syntax

Public Function hashHexFromHex(szMsgHex As String, nOptions As Long) As String

.NET Equivalent

Hash.HexFromHex Method

Python Equivalent

static Hash.hex_from_hex(datahex, alg=Alg.SHA1)

Remarks

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters is API_MAX_HASH_CHARS. The final digest will be truncated to the specified length if less than the expected size. Only lower-case letters [a-f] are used in the output.

Example (VBA core function)

Dim strDigest As String
Dim nRet As Long
Dim strData As String
strDigest = String(API_SHA1_CHARS, " ")
strData = "616263"
nRet = HASH_HexFromHex(strDigest, Len(strDigest), strData, API_HASH_SHA1)
Debug.Print strDigest

Example (VBA wrapper function)

Dim lpMessage() As Byte
lpMessage = StrConv("abc", vbFromUnicode)
Debug.Print "lpMessage=" & cnvHexStrFromBytes(lpMessage)

Debug.Print "OK:" & vbCrLf & "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
Debug.Print hashHexFromBytes(lpMessage, API_HASH_SHA256)
Debug.Print hashHexFromHex("616263", API_HASH_SHA256)
Debug.Print hashHexFromFile("abc.txt", API_HASH_SHA256)
Debug.Print cnvHexStrFromBytes(hashBytes(lpMessage, API_HASH_SHA256))
Debug.Print cnvHexStrFromBytes(hashFile("abc.txt", API_HASH_SHA256))

See Also

HASH_HexFromBytes HASH_Bytes

[Contents] [Index]

[PREV: HASH_HexFromFile...]   [Contents]   [Index]   
   [NEXT: HASH_Init...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.