public GenerateCounterSigners ( |
||
signer | ||
Результат |
public void TestSha1WithRsaCounterSignature() { IList certList = new ArrayList(); IList crlList = new ArrayList(); CmsProcessable msg = new CmsProcessableByteArray(Encoding.ASCII.GetBytes("Hello World!")); certList.Add(SignCert); certList.Add(OrigCert); crlList.Add(SignCrl); IX509Store x509Certs = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(certList)); IX509Store x509Crls = X509StoreFactory.Create( "CRL/Collection", new X509CollectionStoreParameters(crlList)); CmsSignedDataGenerator gen = new CmsSignedDataGenerator(); gen.AddSigner(SignKP.Private, SignCert, CmsSignedDataGenerator.DigestSha1); gen.AddCertificates(x509Certs); gen.AddCrls(x509Crls); CmsSignedData s = gen.Generate(msg, true); SignerInformation origSigner = (SignerInformation) new ArrayList(s.GetSignerInfos().GetSigners())[0]; SignerInformationStore counterSigners1 = gen.GenerateCounterSigners(origSigner); SignerInformationStore counterSigners2 = gen.GenerateCounterSigners(origSigner); SignerInformation signer1 = SignerInformation.AddCounterSigners(origSigner, counterSigners1); SignerInformation signer2 = SignerInformation.AddCounterSigners(signer1, counterSigners2); SignerInformationStore cs = signer2.GetCounterSignatures(); ICollection csSigners = cs.GetSigners(); Assert.AreEqual(2, csSigners.Count); foreach (SignerInformation cSigner in csSigners) { ICollection certCollection = x509Certs.GetMatches(cSigner.SignerID); IEnumerator certEnum = certCollection.GetEnumerator(); certEnum.MoveNext(); X509Certificate cert = (X509Certificate) certEnum.Current; Assert.IsNull(cSigner.SignedAttributes[Asn1.Pkcs.PkcsObjectIdentifiers.Pkcs9AtContentType]); Assert.IsTrue(cSigner.Verify(cert)); } }