Esempio n. 1
0
 Pkcs7CertificateStore(IntPtr handle, Crypt32.CRYPTOAPI_BLOB blob)
 {
     _handle = handle;
     try
     {
         _blob  = blob;
         _store = new X509Store(_handle);
     }
     catch
     {
         //We need to manually clean up the handle here. If we throw here for whatever reason,
         //we'll leak the handle because we'll have a partially constructed object that won't get
         //a finalizer called on or anything to dispose of.
         FreeHandle();
         throw;
     }
 }
Esempio n. 2
0
        public static Pkcs7CertificateStore Create(byte[] data)
        {
            const string STORE_TYPE = "PKCS7";
            var          dataPtr    = Marshal.AllocHGlobal(data.Length);

            Marshal.Copy(data, 0, dataPtr, data.Length);
            var blob = new Crypt32.CRYPTOAPI_BLOB
            {
                cbData = (uint)data.Length,
                pbData = dataPtr
            };
            var handle = Crypt32.CertOpenStore(STORE_TYPE, Crypt32.CertEncodingType.NONE, IntPtr.Zero, Crypt32.CertOpenStoreFlags.NONE, ref blob);

            if (handle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Failed to create a memory certificate store.");
            }
            return(new Pkcs7CertificateStore(handle, blob));
        }