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); }
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); }
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); }
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); }