/// <summary> /// Gets signed mime content. Value null means no content. /// </summary> /// <returns>Returns signed mime content. Value null means no content.</returns> /// <remarks>This method is valid only if <b>Content-Type</b> parameter <b>smime-type=signed-data</b>.</remarks> /// <exception cref="InvalidOperationException">Is raised when <b>smime-type != signed-data</b>.</exception> public MIME_Message GetSignedMime() { if (!string.Equals(this.Entity.ContentType.Parameters["smime-type"], "signed-data", StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidOperationException("The VerifySignature method is only valid if Content-Type parameter smime-type=signed-data."); } if (this.Data != null) { SignedCms signedCms = new SignedCms(); signedCms.Decode(this.Data); return(MIME_Message.ParseFromStream(new MemoryStream(signedCms.ContentInfo.Content))); } else { return(null); } }
/// <summary> /// Decrypts enveloped mime content. /// </summary> /// <param name="cert">Decrypting certificate.</param> /// <returns>Returns decrypted enveloped mime content.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>cert</b> is null reference.</exception> /// <exception cref="InvalidOperationException">Is raised when <b>smime-type != enveloped-data</b>.</exception> public MIME_Message GetEnvelopedMime(X509Certificate2 cert) { if (cert == null) { throw new ArgumentNullException("cert"); } if (!string.Equals(this.Entity.ContentType.Parameters["smime-type"], "enveloped-data", StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidOperationException("The VerifySignature method is only valid if Content-Type parameter smime-type=enveloped-data."); } EnvelopedCms envelopedCms = new EnvelopedCms(); envelopedCms.Decode(this.Data); X509Certificate2Collection certificates = new X509Certificate2Collection(cert); envelopedCms.Decrypt(certificates); return(MIME_Message.ParseFromStream(new MemoryStream(envelopedCms.Encode()))); }