private static System.Security.Cryptography.SafeCertStoreHandle BuildDecryptorStore(X509Certificate2Collection extraStore)
{
X509Certificate2Collection collection = new X509Certificate2Collection();
try
{
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.IncludeArchived | OpenFlags.OpenExistingOnly);
collection.AddRange(store.Certificates);
}
catch (SecurityException)
{
}
try
{
X509Store store2 = new X509Store("MY", StoreLocation.LocalMachine);
store2.Open(OpenFlags.IncludeArchived | OpenFlags.OpenExistingOnly);
collection.AddRange(store2.Certificates);
}
catch (SecurityException)
{
}
if (extraStore != null)
{
collection.AddRange(extraStore);
}
if (collection.Count == 0)
{
throw new CryptographicException(-2146889717);
}
return System.Security.Cryptography.X509Certificates.X509Utils.ExportToMemoryStore(collection);
}