public static SignerInformation AddCounterSigners(SignerInformation signerInformation, SignerInformationStore counterSigners) { Org.BouncyCastle.Asn1.Cms.SignerInfo signerInfo = signerInformation.info; Org.BouncyCastle.Asn1.Cms.AttributeTable unsignedAttributes = signerInformation.UnsignedAttributes; Asn1EncodableVector asn1EncodableVector; if (unsignedAttributes != null) { asn1EncodableVector = unsignedAttributes.ToAsn1EncodableVector(); } else { asn1EncodableVector = new Asn1EncodableVector(new Asn1Encodable[0]); } Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(new Asn1Encodable[0]); foreach (SignerInformation signerInformation2 in counterSigners.GetSigners()) { asn1EncodableVector2.Add(new Asn1Encodable[] { signerInformation2.ToSignerInfo() }); } asn1EncodableVector.Add(new Asn1Encodable[] { new Org.BouncyCastle.Asn1.Cms.Attribute(CmsAttributes.CounterSignature, new DerSet(asn1EncodableVector2)) }); return(new SignerInformation(new Org.BouncyCastle.Asn1.Cms.SignerInfo(signerInfo.SignerID, signerInfo.DigestAlgorithm, signerInfo.AuthenticatedAttributes, signerInfo.DigestEncryptionAlgorithm, signerInfo.EncryptedDigest, new DerSet(asn1EncodableVector)), signerInformation.contentType, signerInformation.content, null)); }
protected internal virtual Asn1Set GetAttributeSet(Org.BouncyCastle.Asn1.Cms.AttributeTable attr) { if (attr != null) { return(new DerSet(attr.ToAsn1EncodableVector())); } return(null); }
public static SignerInformation ReplaceUnsignedAttributes(SignerInformation signerInformation, Org.BouncyCastle.Asn1.Cms.AttributeTable unsignedAttributes) { Org.BouncyCastle.Asn1.Cms.SignerInfo signerInfo = signerInformation.info; Asn1Set unauthenticatedAttributes = null; if (unsignedAttributes != null) { unauthenticatedAttributes = new DerSet(unsignedAttributes.ToAsn1EncodableVector()); } return(new SignerInformation(new Org.BouncyCastle.Asn1.Cms.SignerInfo(signerInfo.SignerID, signerInfo.DigestAlgorithm, signerInfo.AuthenticatedAttributes, signerInfo.DigestEncryptionAlgorithm, signerInfo.EncryptedDigest, unauthenticatedAttributes), signerInformation.contentType, signerInformation.content, null)); }
public override void Close() { Platform.Dispose((Stream)(object)_out); _eiGen.Close(); if (_outer.unprotectedAttributeGenerator != null) { Org.BouncyCastle.Asn1.Cms.AttributeTable attributes = _outer.unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); Asn1Set obj = new BerSet(attributes.ToAsn1EncodableVector()); _envGen.AddObject(new DerTaggedObject(explicitly: false, 1, obj)); } _envGen.Close(); _cGen.Close(); base.Close(); }
public override void Close() { this._out.Close(); this._eiGen.Close(); if (this._outer.unprotectedAttributeGenerator != null) { Org.BouncyCastle.Asn1.Cms.AttributeTable attributes = this._outer.unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); Asn1Set obj = new BerSet(attributes.ToAsn1EncodableVector()); this._envGen.AddObject(new DerTaggedObject(false, 1, obj)); } this._envGen.Close(); this._cGen.Close(); base.Close(); }
public override void PerformTest() { Asn1EncodableVector v = new Asn1EncodableVector( new Asn1Cms.Attribute(type1, new DerSet(type1)), new Asn1Cms.Attribute(type2, new DerSet(type2))); Asn1Cms.AttributeTable table = new Asn1Cms.AttributeTable(v); Asn1Cms.Attribute a = table[type1]; if (a == null) { Fail("type1 attribute not found."); } if (!a.AttrValues.Equals(new DerSet(type1))) { Fail("wrong value retrieved for type1!"); } a = table[type2]; if (a == null) { Fail("type2 attribute not found."); } if (!a.AttrValues.Equals(new DerSet(type2))) { Fail("wrong value retrieved for type2!"); } a = table[type3]; if (a != null) { Fail("type3 attribute found when none expected."); } Asn1EncodableVector vec = table.GetAll(type1); if (vec.Count != 1) { Fail("wrong vector size for type1."); } vec = table.GetAll(type3); if (vec.Count != 0) { Fail("wrong vector size for type3."); } vec = table.ToAsn1EncodableVector(); if (vec.Count != 2) { Fail("wrong vector size for single."); } IDictionary t = table.ToDictionary(); if (t.Count != 2) { Fail("hashtable wrong size."); } // multiple v = new Asn1EncodableVector( new Asn1Cms.Attribute(type1, new DerSet(type1)), new Asn1Cms.Attribute(type1, new DerSet(type2)), new Asn1Cms.Attribute(type1, new DerSet(type3)), new Asn1Cms.Attribute(type2, new DerSet(type2))); table = new Asn1Cms.AttributeTable(v); a = table[type1]; if (!a.AttrValues.Equals(new DerSet(type1))) { Fail("wrong value retrieved for type1 multi Get!"); } vec = table.GetAll(type1); if (vec.Count != 3) { Fail("wrong vector size for multiple type1."); } a = (Asn1Cms.Attribute)vec[0]; if (!a.AttrValues.Equals(new DerSet(type1))) { Fail("wrong value retrieved for type1(0)!"); } a = (Asn1Cms.Attribute)vec[1]; if (!a.AttrValues.Equals(new DerSet(type2))) { Fail("wrong value retrieved for type1(1)!"); } a = (Asn1Cms.Attribute)vec[2]; if (!a.AttrValues.Equals(new DerSet(type3))) { Fail("wrong value retrieved for type1(2)!"); } vec = table.GetAll(type2); if (vec.Count != 1) { Fail("wrong vector size for multiple type2."); } vec = table.ToAsn1EncodableVector(); if (vec.Count != 4) { Fail("wrong vector size for multiple."); } }
private CmsEnvelopedData Generate(CmsProcessable content, string encryptionOid, CipherKeyGenerator keyGen) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0096: Expected O, but got Unknown AlgorithmIdentifier algorithmIdentifier = null; KeyParameter keyParameter; Asn1OctetString encryptedContent; try { byte[] array = keyGen.GenerateKey(); keyParameter = ParameterUtilities.CreateKeyParameter(encryptionOid, array); Asn1Encodable asn1Params = GenerateAsn1Parameters(encryptionOid, array); algorithmIdentifier = GetAlgorithmIdentifier(encryptionOid, keyParameter, asn1Params, out var cipherParameters); IBufferedCipher cipher = CipherUtilities.GetCipher(encryptionOid); cipher.Init(forEncryption: true, new ParametersWithRandom(cipherParameters, rand)); MemoryStream val = new MemoryStream(); CipherStream cipherStream = new CipherStream((Stream)(object)val, null, cipher); content.Write((Stream)(object)cipherStream); Platform.Dispose((Stream)(object)cipherStream); encryptedContent = new BerOctetString(val.ToArray()); } catch (SecurityUtilityException e) { throw new CmsException("couldn't create cipher.", e); } catch (InvalidKeyException e2) { throw new CmsException("key invalid in message.", e2); } catch (IOException val2) { IOException e3 = val2; throw new CmsException("exception decoding algorithm parameters.", (global::System.Exception)(object) e3); } Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(); global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)recipientInfoGenerators).GetEnumerator(); try { while (enumerator.MoveNext()) { RecipientInfoGenerator recipientInfoGenerator = (RecipientInfoGenerator)enumerator.get_Current(); try { asn1EncodableVector.Add(recipientInfoGenerator.Generate(keyParameter, rand)); } catch (InvalidKeyException e4) { throw new CmsException("key inappropriate for algorithm.", e4); } catch (GeneralSecurityException e5) { throw new CmsException("error making encrypted content.", e5); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } EncryptedContentInfo encryptedContentInfo = new EncryptedContentInfo(CmsObjectIdentifiers.Data, algorithmIdentifier, encryptedContent); Asn1Set unprotectedAttrs = null; if (unprotectedAttributeGenerator != null) { Org.BouncyCastle.Asn1.Cms.AttributeTable attributes = unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); unprotectedAttrs = new BerSet(attributes.ToAsn1EncodableVector()); } ContentInfo contentInfo = new ContentInfo(CmsObjectIdentifiers.EnvelopedData, new EnvelopedData(null, new DerSet(asn1EncodableVector), encryptedContentInfo, unprotectedAttrs)); return(new CmsEnvelopedData(contentInfo)); }
private CmsEnvelopedData Generate(CmsProcessable content, string encryptionOid, CipherKeyGenerator keyGen) { AlgorithmIdentifier algorithmIdentifier = null; KeyParameter keyParameter; Asn1OctetString encryptedContent; try { byte[] array = keyGen.GenerateKey(); keyParameter = ParameterUtilities.CreateKeyParameter(encryptionOid, array); Asn1Encodable asn1Params = GenerateAsn1Parameters(encryptionOid, array); algorithmIdentifier = GetAlgorithmIdentifier(encryptionOid, keyParameter, asn1Params, out ICipherParameters cipherParameters); IBufferedCipher cipher = CipherUtilities.GetCipher(encryptionOid); cipher.Init(forEncryption: true, new ParametersWithRandom(cipherParameters, rand)); MemoryStream memoryStream = new MemoryStream(); CipherStream cipherStream = new CipherStream(memoryStream, null, cipher); content.Write(cipherStream); Platform.Dispose(cipherStream); encryptedContent = new BerOctetString(memoryStream.ToArray()); } catch (SecurityUtilityException e) { throw new CmsException("couldn't create cipher.", e); } catch (InvalidKeyException e2) { throw new CmsException("key invalid in message.", e2); } catch (IOException e3) { throw new CmsException("exception decoding algorithm parameters.", e3); } Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(); foreach (RecipientInfoGenerator recipientInfoGenerator in recipientInfoGenerators) { try { asn1EncodableVector.Add(recipientInfoGenerator.Generate(keyParameter, rand)); } catch (InvalidKeyException e4) { throw new CmsException("key inappropriate for algorithm.", e4); } catch (GeneralSecurityException e5) { throw new CmsException("error making encrypted content.", e5); } } EncryptedContentInfo encryptedContentInfo = new EncryptedContentInfo(CmsObjectIdentifiers.Data, algorithmIdentifier, encryptedContent); Asn1Set unprotectedAttrs = null; if (unprotectedAttributeGenerator != null) { Org.BouncyCastle.Asn1.Cms.AttributeTable attributes = unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); unprotectedAttrs = new BerSet(attributes.ToAsn1EncodableVector()); } ContentInfo contentInfo = new ContentInfo(CmsObjectIdentifiers.EnvelopedData, new EnvelopedData(null, new DerSet(asn1EncodableVector), encryptedContentInfo, unprotectedAttrs)); return(new CmsEnvelopedData(contentInfo)); }
public static SignerInformation AddCounterSigners(SignerInformation signerInformation, SignerInformationStore counterSigners) { Org.BouncyCastle.Asn1.Cms.SignerInfo signerInfo = signerInformation.info; Org.BouncyCastle.Asn1.Cms.AttributeTable unsignedAttributes = signerInformation.UnsignedAttributes; Asn1EncodableVector asn1EncodableVector = ((unsignedAttributes == null) ? new Asn1EncodableVector() : unsignedAttributes.ToAsn1EncodableVector()); Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(); global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)counterSigners.GetSigners()).GetEnumerator(); try { while (enumerator.MoveNext()) { SignerInformation signerInformation2 = (SignerInformation)enumerator.get_Current(); asn1EncodableVector2.Add(signerInformation2.ToSignerInfo()); } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } asn1EncodableVector.Add(new Attribute(CmsAttributes.CounterSignature, new DerSet(asn1EncodableVector2))); return(new SignerInformation(new Org.BouncyCastle.Asn1.Cms.SignerInfo(signerInfo.SignerID, signerInfo.DigestAlgorithm, signerInfo.AuthenticatedAttributes, signerInfo.DigestEncryptionAlgorithm, signerInfo.EncryptedDigest, new DerSet(asn1EncodableVector)), signerInformation.contentType, signerInformation.content, null)); }