本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2Collection.Clear方法的具体用法?C# X509Certificate2Collection.Clear怎么用?C# X509Certificate2Collection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509Certificate2Collection
的用法示例。
在下文中一共展示了X509Certificate2Collection.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelfSignedTest
public void SelfSignedTest()
{
var chain = new X509Chain();
var trusted = new X509Certificate2Collection();
Assert.IsFalse(chain.Build(Certificates.SelfSigned));
Assert.IsFalse(chain.VerifyWithExtraRoots(Certificates.SelfSigned, trusted));
trusted.Add(Certificates.SelfSigned);
Assert.IsTrue(chain.VerifyWithExtraRoots(Certificates.SelfSigned, trusted));
Assert.IsFalse(chain.Build(Certificates.SelfSigned));
trusted.Clear();
Assert.IsFalse(chain.VerifyWithExtraRoots(Certificates.SelfSigned, trusted));
Assert.IsFalse(chain.Build(Certificates.SelfSigned));
}
示例2: SelfSignedRootTest
public void SelfSignedRootTest()
{
var chain = new X509Chain();
var trusted = new X509Certificate2Collection();
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
Assert.IsFalse(chain.Build(Certificates.SignedBySelfSigned));
Assert.IsFalse(chain.VerifyWithExtraRoots(Certificates.SignedBySelfSigned, trusted));
trusted.Add(Certificates.SelfSigned);
Assert.IsTrue(chain.VerifyWithExtraRoots(Certificates.SignedBySelfSigned, trusted));
Assert.IsFalse(chain.Build(Certificates.SignedBySelfSigned));
trusted.Clear();
Assert.IsFalse(chain.VerifyWithExtraRoots(Certificates.SignedBySelfSigned, trusted));
Assert.IsFalse(chain.Build(Certificates.SignedBySelfSigned));
}
示例3: FilterCertificates
///////////////////////////////////////////////////////////////////////
///
/// <summary>
/// Carry out the filters requested.
/// </summary>
///
static X509Certificate2 FilterCertificates(X509Certificate2Collection certificates) {
int index;
if (0 < certificates.Count && null != sha1) {
certificates = certificates.Find(X509FindType.FindByThumbprint, sha1, false);
}
if (0 < certificates.Count && 0 < subjects.Count) {
foreach (string subject in subjects) {
certificates = certificates.Find(X509FindType.FindBySubjectDistinguishedName, subject, false);
}
}
if (0 < certificates.Count && 0 < issuers.Count) {
foreach (string issuer in issuers) {
certificates = certificates.Find(X509FindType.FindByIssuerDistinguishedName, issuer, false);
}
}
// filter out certificates without a private key.
if (0 < certificates.Count) {
X509Certificate2Collection collection = new X509Certificate2Collection();
for (index = 0; index < certificates.Count; index++) {
try
{
if (certificates[index].PrivateKey != null)
collection.Add(certificates[index]);
}
catch{}
}
certificates.Clear();
certificates = collection;
}
// finally, ask the user to select a certificate if more than one is found.
if (1 < certificates.Count) {
certificates = X509Certificate2UI.SelectFromCollection( certificates , "Certificates", "Please select a certificate", X509SelectionFlag.SingleSelection);
}
if (certificates.Count != 1)
throw new InternalException("Internal error: No valid certificates were found to sign the document.");
return (certificates.Count == 0 ? null : certificates[0]);
}
示例4: ImportFolder
/// <summary>
/// Adds certificates to this store from a folder.
/// </summary>
/// <param name="folderPath">The path to a folder containing certificate files</param>
/// <param name="flags">The <see cref="X509KeyStorageFlags"/> for the keyfile</param>
public void ImportFolder(string folderPath, X509KeyStorageFlags flags)
{
string[] files = System.IO.Directory.GetFiles(folderPath);
if (files.IsNullOrEmpty())
{
return;
}
X509Certificate2Collection certs = new X509Certificate2Collection();
foreach(string filePath in files)
{
certs.Clear();
certs.Import(filePath, null, flags);
this.Add(certs);
}
}