本文整理匯總了C#中System.Security.Cryptography.X509Certificates.X509Store.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Store.ToString方法的具體用法?C# X509Store.ToString怎麽用?C# X509Store.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.Cryptography.X509Certificates.X509Store
的用法示例。
在下文中一共展示了X509Store.ToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetTokenInfo
public static void GetTokenInfo()
{
Program.logLine("Starting GetTokenInfo");
X509Store store = new X509Store("My");
Program.logLine(store.ToString());
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 cert2 in store.Certificates)
{
Program.logLine(cert2.ToString());
if (cert2.HasPrivateKey)
{
Program.logLine("Has Private Key");
try
{
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert2.PrivateKey;
if (rsa == null) continue; // not smart card cert again
if (rsa.CspKeyContainerInfo.HardwareDevice) // sure - smartcard
{
Console.WriteLine("=======================================================================");
Console.WriteLine("Issuer: " + cert2.Issuer);
Console.WriteLine("Subject: " + cert2.Subject);
Console.WriteLine("Serial: " + cert2.SerialNumber);
Console.WriteLine("ProviderName: " + rsa.CspKeyContainerInfo.ProviderName);
Console.WriteLine("KeyContainerName: " + rsa.CspKeyContainerInfo.KeyContainerName);
foreach (X509Extension extension in cert2.Extensions)
{
if (extension.Oid.FriendlyName == "Key Usage")
{
X509KeyUsageExtension ext = (X509KeyUsageExtension)extension;
Console.WriteLine("Key Usage: " + ext.KeyUsages);
}
}
}
}
catch (CryptographicException c)
{
Console.WriteLine("Serial: " + cert2.SerialNumber);
Console.WriteLine("No se tiene acceso a la clave privada" + c.ToString());
}
}
}
}
示例2: GetTrac
/// <summary>
/// Returns an <see cref="ITrac"/> instance which is connected to a <see cref="ServerDetails"/> object.
/// </summary>
/// <param name="serverDetails"></param>
/// <returns></returns>
public static ITrac GetTrac(ServerDetails serverDetails)
{
ITrac trac = XmlRpcProxyGen.Create<ITrac>();
trac.Proxy = WebRequest.DefaultWebProxy;
trac.Url = serverDetails.XmlRpcUrl();
switch (serverDetails.RequiredAuthentication)
{
case AuthenticationTypes.BasicAuthentication:
trac.Credentials = new NetworkCredential(serverDetails.Username, serverDetails.Password);
break;
case AuthenticationTypes.IntegratedAuthentication:
trac.Credentials = CredentialCache.DefaultNetworkCredentials;
break;
case AuthenticationTypes.ClientCertAuthentication:
try
{
X509Store s = new X509Store(StoreName.My, StoreLocation.CurrentUser);
X509Certificate2Collection col;
s.Open(OpenFlags.ReadOnly);
col = s.Certificates.Find(X509FindType.FindBySubjectName, serverDetails.Username, true);
if (col.Count == 1)
{
trac.ClientCertificates.Add(col[0]);
}
else
{
System.Windows.Forms.MessageBox.Show("No or multiple (" + col.Count + ") certificate with name [" + serverDetails.Username + "] found.");
}
s.Close();
}
catch (System.Security.Cryptography.CryptographicException s)
{
System.Windows.Forms.MessageBox.Show("CryptographicException: " + s.ToString());
}
catch (System.Security.SecurityException s)
{
System.Windows.Forms.MessageBox.Show("SecurityException: " + s.ToString());
}
catch (System.ArgumentException s)
{
System.Windows.Forms.MessageBox.Show("ArgumentException: " + s.ToString());
}
break;
case AuthenticationTypes.None:
trac.Credentials = null;
break;
}
return trac;
}