private CertStrToNameW ( int dwCertEncodingType, [ pszX500, int dwStrType, |
||
dwCertEncodingType | int | |
pszX500 | [ | |
dwStrType | int | |
pvReserved | ||
pbEncoded | ||
pcbEncoded | int | |
ppszError | ||
return | int |
/// <summary> /// Encodes a CERT_NAME_BLOB /// </summary> public static void Encode_CERT_NAME_BLOB(string name, ref CERT_NAME_BLOB pName) { int dwSize = 0; IntPtr pBuffer = IntPtr.Zero; try { // reconstruct name using comma as delimeter. name = ChangeSubjectNameDelimiter(name, ','); int bResult = Win32.CertStrToNameW( X509_ASN_ENCODING, name, CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG, IntPtr.Zero, IntPtr.Zero, ref dwSize, IntPtr.Zero); if (bResult == 0) { throw GetLastError(StatusCodes.BadEncodingError, "Could not get size for CERT_X500_NAME_STR."); } pBuffer = Marshal.AllocHGlobal(dwSize); bResult = Win32.CertStrToNameW( X509_ASN_ENCODING, name, CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG, IntPtr.Zero, pBuffer, ref dwSize, IntPtr.Zero); if (bResult == 0) { throw GetLastError(StatusCodes.BadEncodingError, "Could not encode CERT_X500_NAME_STR."); } pName.pbData = pBuffer; pName.cbData = dwSize; pBuffer = IntPtr.Zero; } finally { if (pBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(pBuffer); } } }