CryptStringToBinaryA function

The CryptStringToBinary function converts a formatted string into an array of bytes.

Syntax

BOOL CryptStringToBinaryA(
  LPCSTR pszString,
  DWORD  cchString,
  DWORD  dwFlags,
  BYTE   *pbBinary,
  DWORD  *pcbBinary,
  DWORD  *pdwSkip,
  DWORD  *pdwFlags
);

Parameters

pszString

A pointer to a string that contains the formatted string to be converted.

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.

dwFlags

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 and Windows XP:  This value is not supported.

CRYPT_STRING_STRICT
0x20000000
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.

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.

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.

pdwSkip

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

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.

Value Meaning
CRYPT_STRING_ANY
This variable will receive one of the following values. Each value indicates the actual format of the string.
CRYPT_STRING_BASE64HEADER
CRYPT_STRING_BASE64
CRYPT_STRING_BINARY
CRYPT_STRING_BASE64_ANY
This variable will receive one of the following values. Each value indicates the actual format of the string.
CRYPT_STRING_BASE64HEADER
CRYPT_STRING_BASE64
CRYPT_STRING_HEX_ANY
This variable will receive one of the following values. Each value indicates the actual format of the string.
CRYPT_STRING_HEXADDR
CRYPT_STRING_HEXASCIIADDR
CRYPT_STRING_HEX
CRYPT_STRING_HEXRAW
CRYPT_STRING_HEXASCII

Return Value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE).

Requirements

   
Windows version Windows XP [desktop apps | UWP apps] Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header wincrypt.h
Library Crypt32.lib
DLL Crypt32.dll

See Also

CryptBinaryToString