本文整理匯總了C#中System.Security.Cryptography.X509Certificates.X509Store.AddRange方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Store.AddRange方法的具體用法?C# X509Store.AddRange怎麽用?C# X509Store.AddRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.Cryptography.X509Certificates.X509Store
的用法示例。
在下文中一共展示了X509Store.AddRange方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
private static void Main(string[] args)
{
Task.Run(async () =>
{
Console.WriteLine("Enter PIN: ");
string pin = Console.ReadLine();
WebRequestHandler handler = new WebRequestHandler();
handler.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
using (HttpClient client = new HttpClient(handler, true))
{
client.BaseAddress = new Uri(string.Format(@"https://{0}:{1}", MachineName, RemotePort));
X509Store store = null;
try
{
var response = await client.GetAsync("certs/" + pin);
response.EnsureSuccessStatusCode();
byte[] rawCert = await response.Content.ReadAsByteArrayAsync();
X509Certificate2Collection certs = new X509Certificate2Collection();
certs.Import(rawCert, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.UserKeySet);
store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
X509Certificate2Collection oldCerts = new X509Certificate2Collection();
foreach (var cert in certs)
{
oldCerts.AddRange(store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName, cert.Subject, false));
}
store.RemoveRange(certs);
store.AddRange(certs);
store.Close();
Console.WriteLine("Success");
}
catch (HttpRequestException e)
{
Console.WriteLine("Error communicating with vcremote. Make sure that vcremote is running in secure mode and that a new client cert has been generated.");
}
finally
{
if (store != null)
{
store.Close();
}
}
}
}).Wait();
}
示例2: Import
/// <summary>
/// Imports certificates and keys from a pkcs12-encoded stream.
/// </summary>
/// <remarks>
/// Imports certificates and keys from a pkcs12-encoded stream.
/// </remarks>
/// <param name="stream">The raw certificate and key data.</param>
/// <param name="password">The password to unlock the stream.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="stream"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="password"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// Importing keys is not supported by this cryptography context.
/// </exception>
public override void Import (Stream stream, string password)
{
if (stream == null)
throw new ArgumentNullException ("stream");
if (password == null)
throw new ArgumentNullException ("password");
var rawData = ReadAllBytes (stream);
var store = new X509Store (StoreName.My, StoreLocation);
var certs = new X509Certificate2Collection ();
store.Open (OpenFlags.ReadWrite);
certs.Import (rawData, password, X509KeyStorageFlags.UserKeySet);
store.AddRange (certs);
store.Close ();
}
示例3: Import
/// <summary>
/// Imports certificates and keys from a pkcs12-encoded stream.
/// </summary>
/// <param name="stream">The raw certificate and key data.</param>
/// <param name="password">The password to unlock the stream.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="stream"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="password"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// Importing keys is not supported by this cryptography context.
/// </exception>
public override void Import(Stream stream, string password)
{
if (stream == null)
throw new ArgumentNullException ("stream");
if (password == null)
throw new ArgumentNullException ("password");
byte[] rawData;
if (stream is MemoryBlockStream) {
rawData = ((MemoryBlockStream) stream).ToArray ();
} else if (stream is MemoryStream) {
rawData = ((MemoryStream) stream).ToArray ();
} else {
using (var memory = new MemoryStream ()) {
stream.CopyTo (memory, 4096);
rawData = memory.ToArray ();
}
}
var store = new X509Store (StoreName.My, StoreLocation);
var certs = new X509Certificate2Collection ();
store.Open (OpenFlags.ReadWrite);
certs.Import (rawData, password, X509KeyStorageFlags.UserKeySet);
store.AddRange (certs);
store.Close ();
}
示例4: StoreEntityCertificatesCore
private void StoreEntityCertificatesCore(X509Certificate2Collection certs, StoreName storeName, StoreLocation storeLocation)
{
X509Store x509Store = null;
x509Store = new X509Store(storeName, storeLocation);
x509Store.Open(OpenFlags.ReadWrite | OpenFlags.MaxAllowed);
x509Store.AddRange(certs);
x509Store.Close();
}
示例5: RemoveRange_Empty_Certificate
public void RemoveRange_Empty_Certificate ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.Open (OpenFlags.ReadWrite);
// note: impossible to add cert_empty, so we add something else
// to be sure we'll follow the complete code path (loop) of removal
xs.AddRange (coll);
xs.RemoveRange (new X509Certificate2Collection (cert_empty));
}
示例6: RemoveRange_OpenReadOnly_Existing
public void RemoveRange_OpenReadOnly_Existing ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.Open (OpenFlags.ReadWrite);
xs.AddRange (coll);
xs.Close ();
xs.Open (OpenFlags.ReadOnly);
xs.RemoveRange (coll);
}
示例7: AddRange_OpenReadOnly
public void AddRange_OpenReadOnly ()
{
X509Store xs = new X509Store ("ReadOnlyStore");
xs.Open (OpenFlags.ReadOnly);
xs.AddRange (coll);
}
示例8: AddRange
public void AddRange ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.Open (OpenFlags.ReadWrite);
xs.AddRange (coll);
Assert.AreEqual (coll.Count, xs.Certificates.Count, "Count");
}
示例9: AddRange_Empty_Certificate
public void AddRange_Empty_Certificate ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.Open (OpenFlags.ReadWrite);
xs.AddRange (new X509Certificate2Collection (cert_empty));
}
示例10: AddRange_Empty_ReadOnly
public void AddRange_Empty_ReadOnly ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.Open (OpenFlags.ReadOnly);
xs.AddRange (coll_empty);
Assert.AreEqual (coll_empty.Count, xs.Certificates.Count, "Count");
}
示例11: AddRange_Empty_Closed
public void AddRange_Empty_Closed ()
{
X509Store xs = new X509Store ("ReadWriteStore");
xs.AddRange (coll_empty);
Assert.AreEqual (coll_empty.Count, xs.Certificates.Count, "Count");
}