[DllImport("crypt32.dll", SetLastError=true)]
static extern TODO CertNameToStr(TODO);
Declare Function CertNameToStr Lib "crypt32.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Please add some!
private static readonly uint X509_ASN_ENCODING = 1;
private static readonly uint CERT_OID_NAME_STR = 2;
private static readonly uint CERT_NAME_STR_CRLF_FLAG = 0x08000000;
private static readonly uint CERT_NAME_STR_NO_QUOTING_FLAG = 0x10000000;
private static readonly uint CERT_NAME_STR_REVERSE_FLAG = 0x02000000;
private static readonly uint CERT_SIMPLE_NAME_STR = 0x08000000;
[DllImport("crypt32.dll", SetLastError = true, EntryPoint = "CertNameToStr")]
private static extern uint _certNameToStr(uint dwCertEncodingType, IntPtr pName, uint dwStrType, StringBuilder psz, uint csz);
public static string CertNameToStr(byte[] certName)
{
CERT_NAME_BLOB name;
name.pbData = Marshal.AllocHGlobal(certName.Length);
Marshal.Copy(certName, 0, name.pbData, certName.Length);
name.cbData = (uint)certName.Length;
IntPtr pName = Marshal.AllocHGlobal(certName.Length);
Marshal.StructureToPtr(name, pName, false);
uint dwStrType = CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG | CERT_NAME_STR_NO_QUOTING_FLAG | CERT_NAME_STR_REVERSE_FLAG | CERT_SIMPLE_NAME_STR;
StringBuilder psz = null;
uint ret = _certNameToStr(X509_ASN_ENCODING, pName, dwStrType, psz, 0);
if (ret == 0) return null;
psz = new StringBuilder((int)ret);
ret = _certNameToStr(X509_ASN_ENCODING, pName, dwStrType, psz, ret);
Marshal.FreeHGlobal(name.pbData);
Marshal.FreeHGlobal(pName);
return psz.ToString();
}