CryptStringToBinary function
Applies to: desktop apps only
The CryptStringToBinary function converts a formatted string into an array of bytes.
Syntax
BOOL WINAPI CryptStringToBinary( __in LPCTSTR pszString, __in DWORD cchString, __in DWORD dwFlags, __in BYTE *pbBinary, __inout DWORD *pcbBinary, __out DWORD *pdwSkip, __out DWORD *pdwFlags );
Parameters
- pszString [in]
-
A pointer to a string that contains the formatted string to be converted.
- cchString [in]
-
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.
- dwFlags [in]
-
Indicates the format of the string to be converted. This can be one of the following values.
Value Meaning - CRYPT_STRING_BASE64HEADER
- 0x00000000
Base64, with certificate beginning and ending headers.
- CRYPT_STRING_BASE64
- 0x00000001
Base64, without headers.
- CRYPT_STRING_BINARY
- 0x00000002
Pure binary copy.
- CRYPT_STRING_BASE64REQUESTHEADER
- 0x00000003
Base64, with request beginning and ending headers.
- CRYPT_STRING_HEX
- 0x00000004
Hexadecimal only format.
- CRYPT_STRING_HEXASCII
- 0x00000005
Hexadecimal format with ASCII character display.
- CRYPT_STRING_BASE64_ANY
- 0x00000006
Tries the following, in order:
- CRYPT_STRING_BASE64HEADER
- CRYPT_STRING_BASE64
- CRYPT_STRING_ANY
- 0x00000007
Tries the following, in order:
- CRYPT_STRING_BASE64HEADER
- CRYPT_STRING_BASE64
- CRYPT_STRING_BINARY
- CRYPT_STRING_HEX_ANY
- 0x00000008
Tries the following, in order:
- CRYPT_STRING_HEXADDR
- CRYPT_STRING_HEXASCIIADDR
- CRYPT_STRING_HEX
- CRYPT_STRING_HEXRAW
- CRYPT_STRING_HEXASCII
- CRYPT_STRING_BASE64X509CRLHEADER
- 0x00000009
Base64, with X.509 certificate revocation list (CRL) beginning and ending headers.
- CRYPT_STRING_HEXADDR
- 0x0000000a
Hex, with address display.
- CRYPT_STRING_HEXASCIIADDR
- 0x0000000b
Hex, with ASCII character and address display.
- CRYPT_STRING_HEXRAW
- 0x0000000c
A raw hexadecimal string.
Windows Server 2003, Windows XP, and Windows 2000: This value is not supported.- CRYPT_STRING_STRICT
- 0x20000000
Generate a Secure Hash Algorithm (SHA)-1 hash of the data BLOB. Use this flag to convert a certificate BLOB into digital thumbprint.
Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, and Windows 2000: This value is not supported. - pbBinary [in]
-
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.
- pcbBinary [in, out]
-
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.
- pdwSkip [out]
-
A pointer to a DWORD value that receives the number of characters skipped to reach the beginning of the actual base64 or hexadecimal strings. This parameter is optional and can be NULL if it is not needed.
- pdwFlags [out]
-
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).
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | CryptStringToBinaryW (Unicode) and CryptStringToBinaryA (ANSI) |
See also
Send comments about this topic to Microsoft
Build date: 3/6/2012