Beispiel #1
0
        private void TestPKCS7Signature(object sender, EventArgs e)
        {
            BodyPart b = sender as BodyPart;

            // Now look at the contents of the body as a signature
            System.Security.Cryptography.Pkcs.SignedCms cms = new System.Security.Cryptography.Pkcs.SignedCms();

            cms.Decode(b.Data);

            foreach (var sig in cms.SignerInfos)
            {
                if (sig.Certificate.Subject.Contains(From.Address))
                {
                    TrustedSender = true;

                    break;
                }
            }
        }
        /// <inheritdoc />
        public byte[] Decrypt(byte[] data)
        {
            try
            {
                var env = new System.Security.Cryptography.Pkcs.EnvelopedCms();
                env.Decode(data);
                env.Decrypt(_allSenderCertificates);

                var decryptedData = env.ContentInfo.Content;
                var sig = new System.Security.Cryptography.Pkcs.SignedCms();
                sig.Decode(decryptedData);
                sig.CheckSignature(true);

                var verifiedData = sig.ContentInfo.Content;

                return verifiedData;
            }
            catch (Exception ex)
            {
                throw new ExtraEncryptionException("No certificate for decryption found.", ex);
            }
        }
Beispiel #3
0
        /// <inheritdoc />
        public byte[] Decrypt(byte[] data)
        {
            try
            {
                var env = new System.Security.Cryptography.Pkcs.EnvelopedCms();
                env.Decode(data);
                env.Decrypt(_allSenderCertificates);

                var decryptedData = env.ContentInfo.Content;
                var sig           = new System.Security.Cryptography.Pkcs.SignedCms();
                sig.Decode(decryptedData);
                sig.CheckSignature(true);

                var verifiedData = sig.ContentInfo.Content;

                return(verifiedData);
            }
            catch (Exception ex)
            {
                throw new ExtraEncryptionException("No certificate for decryption found.", ex);
            }
        }