CryptoSys API Library Manual

CNV_HexStrFromBytes

CNV_HexStrFromBytes encodes an array of bytes into a hexadecimal-encoded string.

VB6/VBA Syntax

Public Declare Function CNV_HexStrFromBytes Lib "diCrryptoSys.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByRef abData As Byte, ByVal nBytes As Long) As Long

nRet = CNV_HexStrFromBytes(strOutput, nMaxChars, abData(0), nDataLen)

Parameters

strOutput
[out] String to receive encoded data.
nMaxChars
[in] Long specifying the maximum number of characters to be received.
abData
[in] Byte array of binary data to be encoded.
nDataLen
[in] Long number of bytes to be encoded.

C/C++ Syntax

long _stdcall CNV_HexStrFromBytes(char *output, long out_len, const unsigned char *input, long in_len);

Returns (VB6/C)

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

.NET Equivalent

Cnv.ToHex Method (Byte[])

COM/ASP Equivalent

conv.HexFromBytes
Public Function HexFromBytes(ByVal abData As Variant) As String

See conv.HexFromBytes.

Remarks

The input array may contain bytes of any value. If vbNullString or an empty string ("") is specified for strOutput or zero for nMaxChars, the function will return the maximum possible size of the encoded string. The final result may be smaller. C/C++ programmers should add one to the returned length value when allocating memory.

Example

This wrapper function returns an encoded string directly:

Public Function cnvHexStrFromBytes(abData() As Byte) As String
' Returns hex string encoding of bytes in abData or empty string if error
    Dim strHex As String
    Dim nHexLen As Long
    Dim nDataLen As Long
    
    On Error GoTo CatchEmptyData
    nDataLen = UBound(abData) - LBound(abData) + 1
    nHexLen = CNV_HexStrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    strHex = String$(nHexLen, " ")
    nHexLen = CNV_HexStrFromBytes(strHex, nHexLen, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    cnvHexStrFromBytes = Left$(strHex, nHexLen)
    
CatchEmptyData:

End Function

See Also

CNV_BytesFromHexStr CNV_HexFilter

[Contents] [Index]

[HOME]   [NEXT: CIPHER_KeyWrap...]

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