コード例 #1
0
        /// <summary>
        /// Create the digest signing context.
        /// </summary>
        /// <remarks>
        /// Creates a new digest signing context.
        /// </remarks>
        /// <returns>The digest signer.</returns>
        /// <exception cref="System.NotSupportedException">
        /// The <see cref="DkimSignerBase.SignatureAlgorithm"/> is not supported.
        /// </exception>
        internal protected virtual ISigner CreateSigningContext()
        {
#if ENABLE_NATIVE_DKIM
            return(new SystemSecuritySigner(SignatureAlgorithm, PrivateKey.AsAsymmetricAlgorithm()));
#else
            ISigner signer;

            switch (SignatureAlgorithm)
            {
            case DkimSignatureAlgorithm.RsaSha1:
                signer = new RsaDigestSigner(new Sha1Digest());
                break;

            case DkimSignatureAlgorithm.RsaSha256:
                signer = new RsaDigestSigner(new Sha256Digest());
                break;

            case DkimSignatureAlgorithm.Ed25519Sha256:
                signer = new Ed25519DigestSigner(new Sha256Digest());
                break;

            default:
                throw new NotSupportedException(string.Format("{0} is not supported.", SignatureAlgorithm));
            }

            signer.Init(true, PrivateKey);

            return(signer);
#endif
        }
コード例 #2
0
        /// <summary>
        /// Create the digest signing context.
        /// </summary>
        /// <remarks>
        /// Creates a new digest signing context that uses the specified algorithm.
        /// </remarks>
        /// <param name="algorithm">The DKIM signature algorithm.</param>
        /// <param name="key">The public key.</param>
        /// <returns>The digest signer.</returns>
        internal virtual ISigner CreateVerifyContext(DkimSignatureAlgorithm algorithm, AsymmetricKeyParameter key)
        {
#if ENABLE_NATIVE_DKIM
            return(new SystemSecuritySigner(algorithm, key.AsAsymmetricAlgorithm()));
#else
            ISigner signer;

            switch (algorithm)
            {
            case DkimSignatureAlgorithm.RsaSha1:
                signer = new RsaDigestSigner(new Sha1Digest());
                break;

            case DkimSignatureAlgorithm.RsaSha256:
                signer = new RsaDigestSigner(new Sha256Digest());
                break;

            case DkimSignatureAlgorithm.Ed25519Sha256:
                signer = new Ed25519DigestSigner(new Sha256Digest());
                break;

            default:
                throw new NotSupportedException(string.Format("{0} is not supported.", algorithm));
            }

            signer.Init(key.IsPrivate, key);

            return(signer);
#endif
        }