public CmsEnvelopedDataParser( Stream envelopedData) : base(envelopedData) { this._attrNotRead = true; this.envelopedData = new EnvelopedDataParser( (Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence)); // TODO Validate version? //DerInteger version = this.envelopedData.Version; // // read the recipients // Asn1Set recipientInfos = Asn1Set.GetInstance(this.envelopedData.GetRecipientInfos().ToAsn1Object()); // // read the encrypted content info // EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo(); this._encAlg = encInfo.ContentEncryptionAlgorithm; CmsReadable readable = new CmsProcessableInputStream( ((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream()); CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable( this._encAlg, readable); // // build the RecipientInformationStore // this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore( recipientInfos, secureReadable); }
public CmsAuthenticatedDataParser( Stream envelopedData) : base(envelopedData) { this.authAttrNotRead = true; this.authData = new AuthenticatedDataParser( (Asn1SequenceParser)contentInfo.GetContent(Asn1Tags.Sequence)); // TODO Validate version? //DerInteger version = this.authData.getVersion(); // // read the recipients // Asn1Set recipientInfos = Asn1Set.GetInstance(authData.GetRecipientInfos().ToAsn1Object()); this.macAlg = authData.GetMacAlgorithm(); // // read the authenticated content info // ContentInfoParser data = authData.GetEnapsulatedContentInfo(); CmsReadable readable = new CmsProcessableInputStream( ((Asn1OctetStringParser)data.GetContent(Asn1Tags.OctetString)).GetOctetStream()); CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable( this.macAlg, readable); // // build the RecipientInformationStore // this._recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore( recipientInfos, secureReadable); }
public CmsReadable GetReadable(KeyParameter sKey) { string id = this.algorithm.ObjectID.Id; try { this.mac = MacUtilities.GetMac(id); this.mac.Init(sKey); } 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("error decoding algorithm parameters.", e3); } CmsReadable result; try { result = new CmsProcessableInputStream(new TeeInputStream(this.readable.GetInputStream(), new MacOutputStream(this.mac))); } catch (IOException e4) { throw new CmsException("error reading content.", e4); } return(result); }
public CmsEnvelopedDataParser(Stream envelopedData) : base(envelopedData) { this._attrNotRead = true; this.envelopedData = new EnvelopedDataParser((Asn1SequenceParser)this.contentInfo.GetContent(16)); Asn1Set instance = Asn1Set.GetInstance(this.envelopedData.GetRecipientInfos().ToAsn1Object()); EncryptedContentInfoParser encryptedContentInfo = this.envelopedData.GetEncryptedContentInfo(); this._encAlg = encryptedContentInfo.ContentEncryptionAlgorithm; CmsReadable readable = new CmsProcessableInputStream(((Asn1OctetStringParser)encryptedContentInfo.GetEncryptedContent(4)).GetOctetStream()); CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(this._encAlg, readable); this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(instance, secureReadable); }
} //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown public CmsAuthenticatedDataParser(Stream envelopedData) : base(envelopedData) { authAttrNotRead = true; authData = new AuthenticatedDataParser((Asn1SequenceParser)contentInfo.GetContent(16)); Asn1Set instance = Asn1Set.GetInstance(authData.GetRecipientInfos().ToAsn1Object()); macAlg = authData.GetMacAlgorithm(); ContentInfoParser enapsulatedContentInfo = authData.GetEnapsulatedContentInfo(); CmsReadable readable = new CmsProcessableInputStream(((Asn1OctetStringParser)enapsulatedContentInfo.GetContent(4)).GetOctetStream()); CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(macAlg, readable); _recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(instance, secureReadable); }
public CmsReadable GetReadable(KeyParameter sKey) { try { this.cipher = CipherUtilities.GetCipher(this.algorithm.ObjectID); Asn1Encodable parameters = this.algorithm.Parameters; Asn1Object asn1Object = (parameters == null) ? null : parameters.ToAsn1Object(); ICipherParameters cipherParameters = sKey; if (asn1Object != null && !(asn1Object is Asn1Null)) { cipherParameters = ParameterUtilities.GetCipherParameters(this.algorithm.ObjectID, cipherParameters, asn1Object); } else { string id = this.algorithm.ObjectID.Id; if (id.Equals(CmsEnvelopedGenerator.DesEde3Cbc) || id.Equals("1.3.6.1.4.1.188.7.1.1.2") || id.Equals("1.2.840.113533.7.66.10")) { cipherParameters = new ParametersWithIV(cipherParameters, new byte[8]); } } this.cipher.Init(false, cipherParameters); } 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("error decoding algorithm parameters.", e3); } CmsReadable result; try { result = new CmsProcessableInputStream(new CipherStream(this.readable.GetInputStream(), this.cipher, null)); } catch (IOException e4) { throw new CmsException("error reading content.", e4); } return(result); }
Stream Envelope(CmsRecipientCollection recipients, Stream content) { var cms = new CmsEnvelopedDataGenerator (); int count = 0; foreach (var recipient in recipients) { cms.AddKeyTransRecipient (recipient.Certificate); count++; } if (count == 0) throw new ArgumentException ("No recipients specified.", "recipients"); // FIXME: how to decide which algorithm to use? var input = new CmsProcessableInputStream (content); var envelopedData = cms.Generate (input, CmsEnvelopedGenerator.DesEde3Cbc); return new MemoryStream (envelopedData.GetEncoded (), false); }
/// <summary> /// Compress the specified stream. /// </summary> /// <returns>A new <see cref="MimeKit.Cryptography.ApplicationPkcs7Mime"/> instance /// containing the compressed content.</returns> /// <param name="stream">The stream to compress.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="stream"/> is <c>null</c>. /// </exception> /// <exception cref="Org.BouncyCastle.Cms.CmsException"> /// An error occurred in the cryptographic message syntax subsystem. /// </exception> public ApplicationPkcs7Mime Compress(Stream stream) { if (stream == null) throw new ArgumentNullException ("stream"); var compresser = new CmsCompressedDataGenerator (); var processable = new CmsProcessableInputStream (stream); var compressed = compresser.Generate (processable, CmsCompressedDataGenerator.ZLib); var encoded = compressed.GetEncoded (); return new ApplicationPkcs7Mime (SecureMimeType.CompressedData, new MemoryStream (encoded, false)); }