The CertNameToStr function converts a certificate name blob to a zero-terminated character string.
The string representation of distinguished names specified in RFC 1779 is adhered to. Deviations were made from RFC 1779 by double quoting embedded quotes, quoting empty strings, and not quoting strings containing consecutive spaces. RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are formatted in hexadecimal (For example,#0A56CF).
#include <wincrypt.h>
DWORD WINAPI CertNameToStr(
DWORD dwCertEncodingType, // in
PCERT_NAME_BLOB pName, // in
DWORD dwStrType, // in
LPTSTR pszNameString, // out, optional
DWORD cszNameString // in
);
Encoding type | Value |
---|---|
X509_ASN_ENCODING | 0x00000001 |
Quote the RDN value if it contains leading or trailing white space or one of the following characters: ",", "+", "=", """, "\n", "<", ">", "#" or ";". The quoting character is ". If the RDN Value contains a " it is double quoted (""). For example:
OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
A reason for using this flag is that the names as they occur in the RDN are reversed from the typical manner in which they are displayed.
For example, an RDN in a certificate might look as follows:
Issuer::
[0,0] 2.5.4.7 (L) Internet
[1,0] 2.5.4.10 (O) VeriSign, Inc.
[2,0] 2.5.4.11 (OU) VeriSign Individual Software Publishers CA
It would be displayed as an X500 name string as follows:
<L=Internet, O="VeriSign, Inc.", OU=VeriSign Individual Software Publishers CA>
To interoperate with LDAP and the RFC standards, the displayed X500 name string should be reversed, by specifying CERT_NAME_STR_REVERSE-FLAG, and it would then be displayed as follows:
<OU=VeriSign Individual Software Publishers CA, O="VeriSign, Inc.", L=Internet>
Returns the number of characters converted, including the terminating zero character. If pszNameString is NULL or cszNameString is zero, returns the required size of the destination string.
If pszNameString is not NULL and cszNameString is not zero, the returned pszNameString is always zero terminated.
See Certificate Management Example Code.
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
Unicode: Defined as Unicode and ANSI prototypes.
CertStrToName, CertRDNValueToStr