CryptBinaryToStringA function (wincrypt.h)
The CryptBinaryToString function converts an array of bytes into a formatted string.
Syntax
BOOL CryptBinaryToStringA(
[in] const BYTE *pbBinary,
[in] DWORD cbBinary,
[in] DWORD dwFlags,
[out, optional] LPSTR pszString,
[in, out] DWORD *pcchString
);
Parameters
[in] pbBinary
A pointer to the array of bytes to be converted into a string.
[in] cbBinary
The number of elements in the pbBinary array.
[in] dwFlags
Specifies the format of the resulting formatted string. This parameter can be one of the following values.
Value | Meaning |
---|---|
|
Base64, with certificate beginning and ending headers. |
|
Base64, without headers. |
|
Pure binary copy. |
|
Base64, with request beginning and ending headers. |
|
Hexadecimal only. |
|
Hexadecimal, with ASCII character display. |
|
Base64, with X.509 CRL beginning and ending headers. |
|
Hexadecimal, with address display. |
|
Hexadecimal, with ASCII character and address display. |
|
A raw hexadecimal string.
Windows Server 2003 and Windows XP: This value is not supported. |
|
Base64, without headers, with "+" replaced by "-" and "/" replaced by "_" as defined in RFC 4648 Section 5. |
|
Enforce strict decoding of ASN.1 text formats. Some ASN.1 binary BLOBS can have the first few bytes of the BLOB incorrectly interpreted as Base64 text. In this case, the rest of the text is ignored. Use this flag to enforce complete decoding of the BLOB.
Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not supported. |
In addition to the values above, one or more of the following values can be specified to modify the behavior of the function.
[out, optional] pszString
A pointer to a buffer that receives the converted string. To calculate the number of characters that must be allocated to hold the returned string, set this parameter to NULL. The function will place the required number of characters, including the terminating NULL character, in the value pointed to by pcchString.
[in, out] pcchString
A pointer to a DWORD variable that contains the size, in TCHARs, of the pszString buffer. If pszString is NULL, the function calculates the length of the return string (including the terminating null character) in TCHARs and returns it in this parameter. If pszString is not NULL and big enough, the function converts the binary data into a specified string format including the terminating null character, but pcchString receives the length in TCHARs, not including the terminating null character.
Return value
If the function succeeds, the function returns nonzero (TRUE).
If the function fails, it returns zero (FALSE).
Remarks
With the exception of when CRYPT_STRING_BINARY encoding is used, all strings are appended with a new line sequence. By default, the new line sequence is a CR/LF pair (0x0D/0x0A). If the dwFlags parameter contains the CRYPT_STRING_NOCR flag, then the new line sequence is a LF character (0x0A). If the dwFlags parameter contains the CRYPT_STRING_NOCRLF flag, then no new line sequence is appended to the string.
Note
The wincrypt.h header defines CryptBinaryToString as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2003 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | wincrypt.h |
Library | Crypt32.lib |
DLL | Crypt32.dll |