Пример #1
0
        /// <summary>
        /// Decrypt (optionally) the given message and try to extract signatures
        /// </summary>
        bool DecryptSignatures(IncomingMessage message, X509Certificate2 certificate, out SignedCms signatures, out MimeEntity payload)
        {
            MimeEntity decryptedEntity = null;

            signatures = null;
            payload    = null;

            if (certificate != null)
            {
                decryptedEntity = m_cryptographer.DecryptEntity(message.GetEncryptedBytes(m_cryptographer), certificate);
            }
            else
            {
                decryptedEntity = message.Message;
            }
            if (decryptedEntity == null)
            {
                return(false);
            }

            if (SMIMEStandard.IsContentEnvelopedSignature(decryptedEntity.ParsedContentType))
            {
                signatures = m_cryptographer.DeserializeEnvelopedSignature(decryptedEntity);
                payload    = MimeSerializer.Default.Deserialize <MimeEntity>(signatures.ContentInfo.Content);
            }
            else if (SMIMEStandard.IsContentMultipartSignature(decryptedEntity.ParsedContentType))
            {
                SignedEntity signedEntity = SignedEntity.Load(decryptedEntity);
                signatures = m_cryptographer.DeserializeDetachedSignature(signedEntity);
                payload    = signedEntity.Content;
            }
            else
            {
                throw new AgentException(AgentError.UnsignedMessage);
            }

            return(true);
        }
Пример #2
0
 /// <summary>
 /// Tranforms an enveloped signature to the corresponding <see cref="SignedCms"/>.
 /// SignedCms is in PKCS#7 format.
 /// </summary>
 /// <param name="envelopeEntity">The entity containing the enveloped signature</param>
 /// <returns>the corresponding <see cref="SignedCms"/></returns>
 public SignedCms DeserializeEnvelopedSignature(MimeEntity envelopeEntity)
 {
     return(m_innerSoftwareCryptographer.DeserializeEnvelopedSignature(envelopeEntity));
 }