/// <summary> /// Detects the type of store represented by the path. /// </summary> public static string DetermineStoreType(string storePath) { if (String.IsNullOrEmpty(storePath)) { return(CertificateStoreType.Directory); } if (storePath.StartsWith(LocalMachine, StringComparison.OrdinalIgnoreCase)) { return(CertificateStoreType.X509Store); } if (storePath.StartsWith(CurrentUser, StringComparison.OrdinalIgnoreCase)) { return(CertificateStoreType.X509Store); } foreach (string storeTypeName in CertificateStoreType.RegisteredStoreTypeNames) { ICertificateStoreType storeType = CertificateStoreType.GetCertificateStoreTypeByName(storeTypeName); if (storeType.SupportsStorePath(storePath)) { return(storeTypeName); } } return(CertificateStoreType.Directory); }
/// <summary> /// Returns an object that can be used to access the store. /// </summary> public static ICertificateStore CreateStore(string storeTypeName) { ICertificateStore store = null; if (String.IsNullOrEmpty(storeTypeName)) { return(new CertificateIdentifierCollection()); } switch (storeTypeName) { case CertificateStoreType.X509Store: { store = new X509CertificateStore(); break; } case CertificateStoreType.Directory: { store = new DirectoryCertificateStore(); break; } default: { ICertificateStoreType storeType = CertificateStoreType.GetCertificateStoreTypeByName(storeTypeName); if (storeType != null) { store = storeType.CreateStore(); break; } throw new ArgumentException($"Invalid store type name: {storeTypeName}"); } } return(store); }