CryptStringToBinaryA function (wincrypt.h)
The CryptStringToBinary function converts a formatted string into an array of bytes.
Syntax
BOOL CryptStringToBinaryA(
[in] LPCSTR pszString,
[in] DWORD cchString,
[in] DWORD dwFlags,
[in] BYTE *pbBinary,
[in, out] DWORD *pcbBinary,
[out] DWORD *pdwSkip,
[out] DWORD *pdwFlags
);
Parameters
[in] pszString
A pointer to a string that contains the formatted string to be converted.
[in] cchString
The number of characters of the formatted string to be converted, not including the terminating NULL character. If this parameter is zero, pszString is considered to be a null-terminated string.
[in] dwFlags
Indicates the format of the string to be converted. This can be one of the following values.
Value | Meaning |
---|---|
|
Base64 between lines of the form `-----BEGIN ...-----` and `-----END ...-----`. See Remarks below. |
|
Base64, without headers. |
|
Pure binary copy. |
|
Base64 between lines of the form `-----BEGIN ...-----` and `-----END ...-----`. See Remarks below. |
|
Hexadecimal only format. |
|
Hexadecimal format with ASCII character display. |
|
Tries the following, in order:
|
|
Tries the following, in order:
|
|
Tries the following, in order:
|
|
Base64 between lines of the form `-----BEGIN ...-----` and `-----END ...-----`. See Remarks below. |
|
Hex, with address display. |
|
Hex, with ASCII character and address display. |
|
A raw hexadecimal string.
Windows Server 2003 and Windows XP: This value is not supported. |
|
Set this flag for Base64 data to specify that the end of the binary data contain only white space and at most three equals "=" signs.
Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not supported. |
[in] pbBinary
A pointer to a buffer that receives the returned sequence of bytes. If this parameter is NULL, the function calculates the length of the buffer needed and returns the size, in bytes, of required memory in the DWORD pointed to by pcbBinary.
[in, out] pcbBinary
A pointer to a DWORD variable that, on entry, contains the size, in bytes, of the pbBinary buffer. After the function returns, this variable contains the number of bytes copied to the buffer. If this value is not large enough to contain all of the data, the function fails and GetLastError returns ERROR_MORE_DATA.
If pbBinary is NULL, the DWORD pointed to by pcbBinary is ignored.
[out] pdwSkip
A pointer to a DWORD value that receives the number of characters skipped to reach the beginning of the
-----BEGIN ...-----
header.
If no header is present, then the DWORD is set to zero.
This parameter is optional and can be NULL if it is not needed.
[out] pdwFlags
A pointer to a DWORD value that receives the flags actually used in the conversion. These are the same flags used for the dwFlags parameter. In many cases, these will be the same flags that were passed in the dwFlags parameter. If dwFlags contains one of the following flags, this value will receive a flag that indicates the actual format of the string. This parameter is optional and can be NULL if it is not needed.
Return value
If the function succeeds, the return value is nonzero (TRUE).
If the function fails, the return value is zero (FALSE).
Remarks
The
CRYPT_STRING_BASE64HEADER,
CRYPT_STRING_BASE64REQUESTHEADER,
and
CRYPT_STRING_BASE64X509CRLHEADER
flags are all treated identically by this function:
They attempt to parse the first block of
base64-encoded data between lines of the form
-----BEGIN ...-----
and -----END ...-----
.
The ...
portions are ignored, and they need not match.
If parsing is successful, the value passed in the dwFlags parameter
is returned in the DWORD pointed to by the pdwFlags parameter.
Note that a value of
CRYPT_STRING_BASE64REQUESTHEADER
or
CRYPT_STRING_BASE64X509CRLHEADER
does not mean that a request header or
X.509
certificate revocation list (CRL)
was found.
Note
The wincrypt.h header defines CryptStringToBinary 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 |