public static void TestHandle() { // // Ensure that the Handle property returns a valid CER_CONTEXT pointer. // using (X509Certificate2 c = new X509Certificate2(TestData.MsCertificate)) { IntPtr h = c.Handle; unsafe { Interop.Crypt32.CERT_CONTEXT *pCertContext = (Interop.Crypt32.CERT_CONTEXT *)h; // Does the blob data match? int cbCertEncoded = pCertContext->cbCertEncoded; Assert.Equal(TestData.MsCertificate.Length, cbCertEncoded); byte[] pCertEncoded = new byte[cbCertEncoded]; Marshal.Copy((IntPtr)(pCertContext->pbCertEncoded), pCertEncoded, 0, cbCertEncoded); Assert.Equal(TestData.MsCertificate, pCertEncoded); // Does the serial number match? Interop.Crypt32.CERT_INFO *pCertInfo = pCertContext->pCertInfo; byte[] serialNumber = pCertInfo->SerialNumber.ToByteArray(); byte[] expectedSerial = "b00000000100dd9f3bd08b0aaf11b000000033".HexToByteArray(); Assert.Equal(expectedSerial, serialNumber); } } }
public static unsafe partial bool CertGetIntendedKeyUsage(Interop.Crypt32.CertEncodingType dwCertEncodingType, Interop.Crypt32.CERT_INFO *pCertInfo, out X509KeyUsageFlags pbKeyUsage, int cbKeyUsage);
public static unsafe bool CertGetIntendedKeyUsage(Interop.Crypt32.CertEncodingType dwCertEncodingType, Interop.Crypt32.CERT_INFO *pCertInfo, out X509KeyUsageFlags pbKeyUsage, int cbKeyUsage) { bool result = Interop.Crypt32.CertGetIntendedKeyUsage(dwCertEncodingType, pCertInfo, out Interop.Crypt32.X509KeyUsageFlags x509KeyUsageFlags, cbKeyUsage); pbKeyUsage = (X509KeyUsageFlags)(int)x509KeyUsageFlags; return(result); }
public static unsafe partial int CertVerifyTimeValidity(ref Interop.Crypt32.FILETIME pTimeToVerify, Interop.Crypt32.CERT_INFO *pCertInfo);