public static void Register(X509Certificate2 cert, CertificateContext context) { IntPtr hCertContext = new IntPtr(); hCertContext = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, cert.RawData, (uint)cert.RawData.Length); CRYPT_KEY_PROV_INFO ProvInfo = new CRYPT_KEY_PROV_INFO(); ProvInfo.ContainerName = context.containerName; ProvInfo.ProvName = context.providerName; ProvInfo.ProvType = PROV_RSA_FULL; ProvInfo.Flags = 0; ProvInfo.KeySpec = context.keySpec; ProvInfo.ProvParam = 0; ProvInfo.rgProvParam = new IntPtr(); if (!CertSetCertificateContextProperty(hCertContext, CERT_KEY_PROV_INFO_PROP_ID, 0, ref ProvInfo)) { throw new Exception("Could set certificate's context."); } Debug.WriteLine("Context set!"); IntPtr hCertStore = CertOpenStoreStringPara(CERT_STORE_PROV_SYSTEM_W, 0, new IntPtr(), CERT_STORE_OPEN_EXISTING_FLAG | CERT_SYSTEM_STORE_CURRENT_USER, "My"); if (!CertAddCertificateContextToStore(hCertStore, hCertContext, CERT_STORE_ADD_REPLACE_EXISTING, new IntPtr())) { throw new Exception("Could not add certificate to store."); } }
public RawCert(byte[] bytes, CertificateContext context) { this.bytes = bytes; this.context = context; }
public CertItem(X509Certificate2 cert, CertificateContext context) { this.cert = cert; this.context = context; }
public static void Register(X509Certificate2 cert, CertificateContext context) { IntPtr hCertContext = new IntPtr(); hCertContext = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, cert.RawData,(uint) cert.RawData.Length); CRYPT_KEY_PROV_INFO ProvInfo = new CRYPT_KEY_PROV_INFO(); ProvInfo.ContainerName = context.containerName; ProvInfo.ProvName = context.providerName; ProvInfo.ProvType = PROV_RSA_FULL; ProvInfo.Flags = 0; ProvInfo.KeySpec = context.keySpec; ProvInfo.ProvParam = 0; ProvInfo.rgProvParam = new IntPtr(); if (!CertSetCertificateContextProperty(hCertContext, CERT_KEY_PROV_INFO_PROP_ID, 0, ref ProvInfo)) throw new Exception("Could set certificate's context."); Debug.WriteLine("Context set!"); IntPtr hCertStore = CertOpenStoreStringPara(CERT_STORE_PROV_SYSTEM_W, 0, new IntPtr(), CERT_STORE_OPEN_EXISTING_FLAG | CERT_SYSTEM_STORE_CURRENT_USER, "My"); if (!CertAddCertificateContextToStore(hCertStore, hCertContext, CERT_STORE_ADD_REPLACE_EXISTING, new IntPtr())) throw new Exception("Could not add certificate to store."); }