IX500DistinguishedName::Encode method
Applies to: desktop apps only
The Encode method initializes the object from a string that contains a distinguished name. This method is web enabled.
Syntax
HRESULT Encode( [in] BSTR strName, [in] X500NameFlags NameFlags );
Parameters
- strName [in]
-
A BSTR variable that contains the string to encode.
- NameFlags [in]
-
An X500NameFlags enumeration value that specifies the format of the encoded value.
Note The following flags are set automatically:
- The default value specified in Certenroll.h is XCN_CERT_NAME_STR_NONE.
- If you do not specify XCN_CERT_NAME_STR_FORWARD_FLAG, then XCN_CERT_NAME_STR_REVERSE_FLAG is automatically applied.
- If you do not specify XCN_CERT_NAME_STR_DISABLE_UTF8_DIR_STR_FLAG, then XCN_CERT_NAME_STR_FORCE_UTF8_DIR_STR_FLAG is automatically applied.
- XCN_CERT_NAME_STR_ENABLE_PUNYCODE_FLAG is automatically set regardless of any other flag you specify.
Return value
If the function succeeds, the function returns S_OK.
If the function fails, it returns an HRESULT value that indicates the error. Possible values include, but are not limited to, those in the following table. For a list of common error codes, see Common HRESULT Values.
| Return code/value | Description |
|---|---|
|
Memory could not be allocated for the encoded value. |
|
The strName parameter cannot be NULL. |
|
The length, in characters of the strName parameter cannot exceed 64 * 1024. |
Remarks
This method internally calls the CryptoAPI CertStrToName function. Call the Name property to retrieve the name as a null-terminated character string. Call the EncodedName property to retrieve a string containing an encoded name.
Requirements
|
Minimum supported client | Windows Vista |
|---|---|
|
Minimum supported server | Windows Server 2008 |
|
Header |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 2/3/2012
If you have special character like comma (,) in the common name of the subject and tried to use certreq.exe to create a certificate request, you may have noticed error like Certificate Request Processor: The string contains an invalid X500 name attribute key, oid, value or delimiter. 0x80092023 (-2146885597).
You can actually create the request yourself using new enrollment interface. Basically you need to use semi-colon (;) as the RDN separator instead of comma. An example VBScript is:
const XCN_CERT_NAME_STR_SEMICOLON_FLAG = &H40000000
const ContextUser = 1
const XCN_CRYPT_STRING_BASE64 = 1
set dn = CreateObject("X509Enrollment.CX500DistinguishedName.1")
set req = CreateObject("X509Enrollment.CX509Enrollment.1")
req.Initialize(ContextUser)
set pkcs10 = req.Request
result = dn.Encode("CN=mysurname,myname;C=US", XCN_CERT_NAME_STR_SEMICOLON_FLAG)
pkcs10.Subject = dn
result = pkcs10.Encode
wscript.echo pkcs10.RawDataToBeSigned(XCN_CRYPT_STRING_BASE64)