Example #1
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
        }