Ejemplo n.º 1
0
 public byte[] Export(X509ContentType contentType, string password)
 {
     new StorePermission(StorePermissionFlags.AllFlags).Assert();
     System.Security.Cryptography.SafeCertStoreHandle safeCertStoreHandle = System.Security.Cryptography.X509Certificates.X509Utils.ExportToMemoryStore(this);
     byte[] buffer = ExportCertificatesToBlob(safeCertStoreHandle, contentType, password);
     safeCertStoreHandle.Dispose();
     return(buffer);
 }
Ejemplo n.º 2
0
        public X509Certificate2Collection Find(X509FindType findType, object findValue, bool validOnly)
        {
            new StorePermission(StorePermissionFlags.AllFlags).Assert();
            System.Security.Cryptography.SafeCertStoreHandle safeSourceStoreHandle = System.Security.Cryptography.X509Certificates.X509Utils.ExportToMemoryStore(this);
            System.Security.Cryptography.SafeCertStoreHandle safeCertStoreHandle   = FindCertInStore(safeSourceStoreHandle, findType, findValue, validOnly);
            X509Certificate2Collection certificates = System.Security.Cryptography.X509Certificates.X509Utils.GetCertificates(safeCertStoreHandle);

            safeCertStoreHandle.Dispose();
            safeSourceStoreHandle.Dispose();
            return(certificates);
        }
Ejemplo n.º 3
0
        public void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
        {
            uint dwFlags = System.Security.Cryptography.X509Certificates.X509Utils.MapKeyStorageFlags(keyStorageFlags);

            System.Security.Cryptography.SafeCertStoreHandle invalidHandle = System.Security.Cryptography.SafeCertStoreHandle.InvalidHandle;
            new StorePermission(StorePermissionFlags.AllFlags).Assert();
            invalidHandle = LoadStoreFromFile(fileName, password, dwFlags, (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != X509KeyStorageFlags.DefaultKeySet);
            X509Certificate2Collection certificates = System.Security.Cryptography.X509Certificates.X509Utils.GetCertificates(invalidHandle);

            invalidHandle.Dispose();
            X509Certificate2[] array = new X509Certificate2[certificates.Count];
            certificates.CopyTo(array, 0);
            this.AddRange(array);
        }
Ejemplo n.º 4
0
        private static unsafe System.Security.Cryptography.SafeCertStoreHandle LoadStoreFromFile(string fileName, string password, uint dwFlags, bool persistKeyContainers)
        {
            uint num = 0;

            System.Security.Cryptography.SafeCertStoreHandle invalidHandle = System.Security.Cryptography.SafeCertStoreHandle.InvalidHandle;
            if (!CAPI.CryptQueryObject(1, fileName, 0x1732, 14, 0, IntPtr.Zero, new IntPtr((void *)&num), IntPtr.Zero, ref invalidHandle, IntPtr.Zero, IntPtr.Zero))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            if (num == 12)
            {
                invalidHandle.Dispose();
                invalidHandle = CAPI.PFXImportCertStore(1, fileName, password, dwFlags, persistKeyContainers);
            }
            if ((invalidHandle == null) || invalidHandle.IsInvalid)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            return(invalidHandle);
        }