本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Store类的典型用法代码示例。如果您正苦于以下问题:C# X509Store类的具体用法?C# X509Store怎么用?C# X509Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509Store类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X509Store类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Load
public static X509Store Load(string file, string password) {
if (file == null || password == null) {
return null;
}
if (!File.Exists(file)) {
throw new FileNotFoundException("", file);
}
var fileContents = File.ReadAllBytes(file);
var ptr = Marshal.AllocHGlobal(fileContents.Length);
Marshal.Copy(fileContents, 0, ptr, fileContents.Length);
var cryptBlob = new CRYPT_DATA_BLOB {
cbData = (uint)fileContents.Length,
pbData = ptr
};
if (!PFXIsPFXBlob(ref cryptBlob)) {
return null;
}
if (!PFXVerifyPassword(ref cryptBlob, password)) {
return null;
}
X509Store store = null;
var storePtr = PFXImportCertStore(ref cryptBlob, password);
store = new X509Store(storePtr);
Marshal.FreeHGlobal(ptr);
return store;
}
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:29,代码来源:PfxStoreLoader.cs
示例2: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings)
{
cancelToken = cancelTokenSrc.Token;
appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
if (appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
certificates.Add(certificate);
if (this.appleSettings.AdditionalCertificates != null)
foreach (var addlCert in this.appleSettings.AdditionalCertificates)
certificates.Add(addlCert);
timerCleanup = new Timer(state => Cleanup(), null, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000));
}
开发者ID:vniu,项目名称:PushSharp,代码行数:27,代码来源:ApplePushChannel.cs
示例3: GetCertificate
static X509Certificate2 GetCertificate(string certFindValue)
{
StoreLocation[] locations = new StoreLocation[] { StoreLocation.LocalMachine, StoreLocation.CurrentUser };
foreach (StoreLocation location in locations)
{
X509Store store = new X509Store(StoreName.My, location);
store.Open(OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = store.Certificates.Find(
X509FindType.FindBySubjectName,
certFindValue,
false);
if (collection.Count == 0)
{
collection = store.Certificates.Find(
X509FindType.FindByThumbprint,
certFindValue,
false);
}
store.Close();
if (collection.Count > 0)
{
return collection[0];
}
}
throw new ArgumentException("No certificate can be found using the find value " + certFindValue);
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:31,代码来源:Program.cs
示例4: GetServerCertificate
private static X509Certificate GetServerCertificate()
{
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509CertificateCollection cert = store.Certificates.Find(X509FindType.FindBySubjectName, "LocalHost", true);
return cert[0];
}
开发者ID:Siryu,项目名称:Distributed-Processing-Capstone,代码行数:7,代码来源:ServerSecureSocket.cs
示例5: GetCertificate
public static X509Certificate2 GetCertificate(string serialNumber)
{
List<string> list = new List<string>();
X509Store storeCurUser = new X509Store(StoreLocation.CurrentUser);
storeCurUser.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in storeCurUser.Certificates)
{
if (mCert.SerialNumber.Contains(serialNumber))
{
return mCert;
}
}
X509Store storeMachine = new X509Store(StoreLocation.LocalMachine);
storeMachine.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in storeMachine.Certificates)
{
if (mCert.SerialNumber.Contains(serialNumber))
{
return mCert;
}
}
return null;
}
开发者ID:ozeraydin57,项目名称:Addon-SAP-B1-Default,代码行数:29,代码来源:CertificateUtil.cs
示例6: GcmXmppConnection
public GcmXmppConnection (GcmXmppConfiguration configuration)
{
authCompletion = new TaskCompletionSource<bool> ();
notifications = new Dictionary<string,CompletableNotification> ();
Configuration = configuration;
certificates = new X509CertificateCollection ();
// Add local/machine certificate stores to our collection if requested
//if (Configuration.AddLocalAndMachineCertificateStores) {
var store = new X509Store (StoreLocation.LocalMachine);
certificates.AddRange (store.Certificates);
store = new X509Store (StoreLocation.CurrentUser);
certificates.AddRange (store.Certificates);
//}
// Add optionally specified additional certs into our collection
// if (Configuration.AdditionalCertificates != null) {
// foreach (var addlCert in Configuration.AdditionalCertificates)
// certificates.Add (addlCert);
// }
// Finally, add the main private cert for authenticating to our collection
// if (certificate != null)
// certificates.Add (certificate);
}
开发者ID:CalebKoch,项目名称:PushSharp,代码行数:28,代码来源:GcmXmppConnection.cs
示例7: Initialize
internal static X509Certificate Initialize(ICertificateConfig cerConfig)
{
if (!string.IsNullOrEmpty(cerConfig.FilePath))
{
//To keep compatible with website hosting
string filePath;
if (Path.IsPathRooted(cerConfig.FilePath))
filePath = cerConfig.FilePath;
else
{
filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, cerConfig.FilePath);
}
return new X509Certificate2(filePath, cerConfig.Password);
}
else
{
var storeName = cerConfig.StoreName;
if (string.IsNullOrEmpty(storeName))
storeName = "Root";
var store = new X509Store(storeName);
store.Open(OpenFlags.ReadOnly);
var cert = store.Certificates.OfType<X509Certificate2>().Where(c =>
c.Thumbprint.Equals(cerConfig.Thumbprint, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
store.Close();
return cert;
}
}
开发者ID:xxjeng,项目名称:nuxleus,代码行数:34,代码来源:CertificateManager.cs
示例8: Client
private void Client()
{
SocketWatcher c_w = new SocketWatcher(20);
c_w.Synchronous = true;
// Note: must have a client cert in your IE cert store.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
if (store.Certificates.Count > 0)
{
c_w.LocalCertificate = store.Certificates[0];
}
else
{
lock (done)
{
errorMessage = "There were no certificates in the Windows Certificate Store.";
succeeded = false;
Monitor.Pulse(done);
}
return;
}
c_w.CreateConnectSocket(this, a, true, "localhost");
}
开发者ID:sq5gvm,项目名称:JabberNet-2010,代码行数:27,代码来源:SSLAsyncSocketTest.cs
示例9: GetCertificate
/// <summary>
/// Gets a X509 certificate from windows store. Asks the user for the correct certificate.
/// </summary>
/// <returns></returns>
public static X509Certificate2 GetCertificate()
{
var st = new X509Store(StoreName.My, StoreLocation.CurrentUser);
st.Open(OpenFlags.ReadOnly);
X509Certificate2 card = null;
try
{
X509Certificate2Collection col = st.Certificates;
X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(col, "Certificates",
"Select one to sign",
X509SelectionFlag.
SingleSelection);
if (sel.Count > 0)
{
X509Certificate2Enumerator en = sel.GetEnumerator();
en.MoveNext();
card = en.Current;
}
}
finally
{
st.Close();
}
return card;
}
开发者ID:rag2111,项目名称:Hexa.Core,代码行数:29,代码来源:CertificateHelper.cs
示例10: OnValidationCallback
public bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
if (errors.ToString() != "None")
{
MessageBox.Show("Please click yes on the next dialog box.\nThis will allow us to install the Net7 certificate.", "Certificate Install",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
try
{
X509Store Certificate = new X509Store(StoreName.Root);
X509Certificate2 cert2 = new X509Certificate2(cert);
Certificate.Open(OpenFlags.ReadWrite);
// Add Certificate
Certificate.Add(cert2);
Certificate.Close();
}
catch (Exception e)
{
MessageBox.Show("Error installing certificate: " + e.ToString());
}
}
else
{
MessageBox.Show("Certificate is installed!");
}
// Remove this message
ServicePointManager.ServerCertificateValidationCallback = null;
return true;
}
开发者ID:RavenB,项目名称:Earth-and-Beyond-server,代码行数:34,代码来源:FormMain.cs
示例11: CertificateStore
public CertificateStore(string machine)
{
var storename = String.IsNullOrEmpty(machine) || String.Compare("localhost", machine, StringComparison.OrdinalIgnoreCase) == 0
? "MY"
: @"\\{0}\MY".FormatWith(machine);
_store = new X509Store(storename.FormatWith(machine), StoreLocation.LocalMachine);
}
开发者ID:laazyj,项目名称:dropkick,代码行数:7,代码来源:CertificateStoreUtility.cs
示例12: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
: base(channelSettings, serviceSettings)
{
this.appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
if (appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
certificates.Add(certificate);
if (this.appleSettings.AdditionalCertificates != null)
foreach (var addlCert in this.appleSettings.AdditionalCertificates)
certificates.Add(addlCert);
//Start our cleanup task
taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning);
taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted);
taskCleanup.Start();
}
开发者ID:ngoossens,项目名称:PushSharp,代码行数:29,代码来源:ApplePushChannel.cs
示例13: AddCertificate
/// <summary>
/// Adds a certificate to a cert store in the local machine.
/// </summary>
/// <param name="certificate">The file path to find the certificate file.</param>
/// <param name="storeName">Name of the certificate store.</param>
/// <param name="storeLocation">Location of the certificate store.</param>
public static void AddCertificate(X509Certificate2 certificate, StoreName storeName, StoreLocation storeLocation)
{
X509Store store = null;
try
{
store = new X509Store(storeName, storeLocation);
store.Open(OpenFlags.ReadOnly | OpenFlags.ReadWrite);
var certificates = from cert in store.Certificates.OfType<X509Certificate2>()
where cert.Thumbprint == certificate.Thumbprint
select cert;
if (certificates.FirstOrDefault() == null)
{
store.Add(certificate);
Console.WriteLine(string.Format("Added certificate with thumbprint {0} to store '{1}', has private key: {2}.", certificate.Thumbprint, storeName.ToString(), certificate.HasPrivateKey));
store.Close();
store = null;
}
}
catch (Exception ex)
{
throw new Exception(String.Format("AddCert exception storeName={0} storeLocation={1}", storeName.ToString(), storeLocation.ToString()), ex);
}
finally
{
if (store != null)
{
store.Close();
}
}
}
开发者ID:hendryluk,项目名称:twitterbigdata,代码行数:40,代码来源:CertificateHelper.cs
示例14: GetCertificates
/// <summary>
/// Gets the physical certificates that match the input certificate from the Local Machine and Trusted People store.
/// </summary>
/// <param name="certificate"></param>
/// <returns></returns>
public static List<X509Certificate2> GetCertificates(Certificate certificate)
{
// If the certificate is null then we have none matching ?
if (certificate == null)
return null;
X509Store x509Store;
try
{
x509Store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
x509Store.Open(OpenFlags.ReadOnly);
}
catch (Exception ex)
{
Logger.Error("Could not access certificate store.", ex);
return null;
}
return x509Store.Certificates.Cast<X509Certificate2>().Where(c => (ContainsCondition(c.Issuer, certificate.Issuer)) &&
(EqualCondition(c.GetPublicKeyString(), certificate.PublicKey)) &&
(EqualCondition(c.GetSerialNumberString(), certificate.SerialNumber)) &&
(ContainsCondition(c.Subject, certificate.Subject)) &&
(EqualCondition(c.GetEffectiveDateString(), certificate.ValidFrom != DateTime.MinValue ? certificate.ValidFrom.ToString() : null)) &&
(EqualCondition(c.GetExpirationDateString(), certificate.ValidTo != DateTime.MinValue ? certificate.ValidTo.ToString() : null))).ToList();
}
开发者ID:sbolofsson,项目名称:OpenBus,代码行数:31,代码来源:CertificateHelper.cs
示例15: GetBySerialNumber
public X509Certificate2 GetBySerialNumber(string serialNumber, StoreLocation storeLocation, StoreName storeName)
{
X509Store store = new X509Store(storeName, storeLocation);
var matchingCertificates = this.findAllCertificatesInStore(store, (s) => { return s.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, true); });
return this.getSingleCertificate(matchingCertificates);
}
开发者ID:dstrucl,项目名称:Tangenta40,代码行数:7,代码来源:Certificates.cs
示例16: FromX509Store
/// <summary>
/// Gets a reference to Certificate store handle in the supplied <see cref="X509Store"/> object.
/// </summary>
/// <param name="store">The store.</param>
/// <returns></returns>
public static CertStoreHandle FromX509Store(X509Store store)
{
if (store == null) return InvalidHandle;
// the handle is owned by the X509Store object. We shouldn't release it!
return new CertStoreHandle(store.StoreHandle, false);
}
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:12,代码来源:CertStoreHandle.cs
示例17: GetCertificate
public X509Certificate2 GetCertificate(string thumbprint, StoreLocation storeLocation)
{
X509Store certStore = new X509Store(StoreName.My, storeLocation);
X509Certificate2 certToUse = null;
try
{
try
{
certStore.Open(OpenFlags.ReadOnly);
}
catch (Exception ex)
{
var outerEx = new Exception("Failed to open X509Store My on CurrentUser.", ex);
throw outerEx;
}
var primaryCertificateThumbprint = thumbprint.ToLower();
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, primaryCertificateThumbprint, false);
if (certCollection == null || certCollection.Count == 0)
{
return null;
}
certToUse = certCollection[0];
if (certToUse.Thumbprint.ToLower() != primaryCertificateThumbprint.ToLower())
{
return null;
}
}
finally
{
certStore.Close();
}
return certToUse;
}
开发者ID:compliashield,项目名称:certificate-issuer,代码行数:34,代码来源:CetificateStore.cs
示例18: GetAppleServerCert
private static X509Certificate GetAppleServerCert(string thumbprint)
{
X509Store store;
store = new X509Store(StoreLocation.CurrentUser);
if (store != null)
{
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates;
if (certs.Count > 0)
{
for (int i = 0; i < certs.Count; i++)
{
X509Certificate2 cert = certs[i];
if (cert.Thumbprint.Equals(thumbprint, StringComparison.InvariantCultureIgnoreCase))
{
return certs[i];
}
}
}
}
Trace.TraceError("Could not find the certification containing: {0} ", "R5QS56362W:R5QS56362W");
throw new InvalidDataException("Could not find the Apple Push Notification certificate");
}
开发者ID:joe-keane,项目名称:dotnet-passbook,代码行数:29,代码来源:SendEmptyPushNotification.cs
示例19: GetX509Certificate2
public static X509Certificate2 GetX509Certificate2(String thumbprint)
{
X509Certificate2 x509Certificate2 = null;
X509Store store = new X509Store("My", StoreLocation.LocalMachine);
try
{
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection x509Certificate2Collection = store.Certificates.Find(X509FindType.FindByThumbprint,
thumbprint,
false);
x509Certificate2 = x509Certificate2Collection[0];
}
catch (Exception ex)
{
Logger.Write(string.Format("Error in GetX509Certificate2(String thumbprint) Error: {0}", ex.Message));
x509Certificate2 = null;
}
finally
{
store.Close();
}
return x509Certificate2;
}
开发者ID:yonglehou,项目名称:Bermuda,代码行数:29,代码来源:CertificateUtility.cs
示例20: LoadCertificateByThumbprint
private bool LoadCertificateByThumbprint(string thumbprint)
{
thumbprint = thumbprint.Replace(" ", "").ToUpperInvariant();
StoreName storeName = StoreName.My;
StoreLocation storeLocation = StoreLocation.LocalMachine;
X509Store store = new X509Store(storeName, storeLocation);
try
{
store.Open(OpenFlags.ReadOnly);
foreach (var cert in store.Certificates)
{
if (cert.HasPrivateKey == false)
continue;
if (String.Compare(cert.Thumbprint, thumbprint) == 0)
{
_certificate = cert;
break;
}
}
}
finally
{
store.Close();
}
if (_certificate == null)
{
throw new InvalidOperationException("The certificate with the thumbprint " + thumbprint + " could not be found.");
}
return true;
}
开发者ID:JulieGueho,项目名称:Encryption,代码行数:35,代码来源:EncryptionService.cs
注:本文中的System.Security.Cryptography.X509Certificates.X509Store类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论