Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than crypt32, prefix the name with the module name and a period.
CertNameToStr (crypt32)
.
Summary
The
CertNameToStr function converts an encoded name in a CERT_NAME_BLOB structure to a null-terminated character string.
C# Signature:
[DllImport("crypt32.dll", SetLastError=true)]
static extern TODO CertNameToStr(TODO);
VB Signature:
Declare Function CertNameToStr Lib "crypt32.dll" (TODO) As TODO
User-Defined Types:
public struct CERT_NAME_BLOB
{
public uint cbData;
public IntPtr pbData;
}
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
None.
Tips & Tricks:
Please add some!
Alternative Managed API:
Do you know one? Please contribute it!
Sample Code:
private static readonly uint X509_ASN_ENCODING = 1;
Notes:
None.
private static readonly uint CERT_SIMPLE_NAME_STR = 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;
Tips & Tricks:
Please add some!
[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)
Sample Code:
public struct CERT_NAME_BLOB
{
uint dwStrType = CERT_SIMPLE_NAME_STR | CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG | CERT_NAME_STR_NO_QUOTING_FLAG | CERT_NAME_STR_REVERSE_FLAG;
StringBuilder psz = null;
public uint cbData;
public IntPtr pbData;
}
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);
private static readonly uint X509_ASN_ENCODING = 1;
try
{
uint ret = _certNameToStr(X509_ASN_ENCODING, pName, dwStrType, psz, 0);
if (ret == 0) return null;
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;
psz = new StringBuilder((int)ret);
ret = _certNameToStr(X509_ASN_ENCODING, pName, dwStrType, psz, ret);
}
finally
{
Marshal.FreeHGlobal(name.pbData);
Marshal.FreeHGlobal(pName);
}
[DllImport("crypt32.dll", SetLastError = true, EntryPoint = "CertNameToStr")]
private static extern uint _certNameToStr(uint dwCertEncodingType, IntPtr pName, uint dwStrType, StringBuilder psz, uint csz);
return psz.ToString();
}
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();
}
Documentation
The CertNameToStr function converts an encoded name in a CERT_NAME_BLOB structure to a null-terminated character string.
6/26/2015 3:26:36 AM - -195.13.239.147
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).