CryptoSys API Library Manual

CNV_BytesFromHexStr

Decodes a hexadecimal-encoded string into an array of Bytes.

VBA/VB6 Syntax

Public Declare Function CNV_BytesFromHexStr Lib "diCryptoSys.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strInput As String) As Long

nRet = CNV_BytesFromHexStr(abData(0), nDataLen, strInput)

C/C++ Syntax

long __stdcall CNV_BytesFromHexStr(unsigned char *lpOutput, long nOutputLen, const char *szInput);

Parameters

lpOutput
[out] array suitably dimensioned to receive output.
nOutputLen
[in] specifying the length of the byte array.
szInput
[in] of hexadecimal data to be decoded.

Returns (VBA/C)

If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function cnvBytesFromHexStr(szHex As String) As Byte()

.NET Equivalent

Cnv.FromHex Method

COM/ASP Equivalent

conv.BytesFromHex
Public Function BytesFromHex(ByVal strHex As String) As Variant

See conv.BytesFromHex.

C++ (STL) Equivalent

static bvec_t crsysapi::Cnv::FromHex (const std::string &s)

Python Equivalent

static Cnv.fromhex(s)

Remarks

Call the function with a zero nOutBytes or NULL lpOutput array to find the required length.

@warning [Changed in v5.2] This function now returns an error if it finds an illegal character in the input string (previously any non-hex character was just ignored). Whitespace characters and ASCII punctuation characters are still allowed and ignored (so "DE:AD:BE:EF" is OK) but obviously non-hex characters like those in the range [G-Zg-z] will cause an error.

Example

Dim strHex As String
Dim abData() As Byte
Dim i As Integer
strHex = "FEDCAB9876543210"
' Convert hex string to bytes
abData = cnvBytesFromHexStr(strHex)
Debug.Print "{";
For i = LBound(abData) To UBound(abData)
    Debug.Print Hex(abData(i)) & ", ";
Next
Debug.Print "}"
strHex = ""
' Convert back to a hex string
strHex = cnvHexStrFromBytes(abData)
Debug.Print strHex

Output:

{FE, DC, AB, 98, 76, 54, 32, 10, }
FEDCAB9876543210

See Also

CNV_HexStrFromBytes CNV_HexFilter

[Contents] [Index]

[PREV: CNV_BytesFromB64Str...]   [Contents]   [Index]   
   [NEXT: CNV_HexFilter...]

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