예제 #1
0
        /// <summary>
        /// Sets the signing credential.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="rsaKey">The RSA key.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">RSA key does not have a private key.</exception>
        public static IHttpSignatureBuilder AddSigningCredential(this IHttpSignatureBuilder builder, RsaSecurityKey rsaKey)
        {
            if (rsaKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist)
            {
                throw new InvalidOperationException("RSA key does not have a private key.");
            }
            var credential = new SigningCredentials(rsaKey, "RS256");

            return(builder.AddSigningCredential(credential));
        }
예제 #2
0
        /// <summary>
        /// Sets the signing credential.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="certificate">The certificate.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException">X509 certificate does not have a private key.</exception>
        public static IHttpSignatureBuilder AddSigningCredential(this IHttpSignatureBuilder builder, X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }
            if (!certificate.HasPrivateKey)
            {
                throw new InvalidOperationException("X509 certificate does not have a private key.");
            }
            var credential = new SigningCredentials(new X509SecurityKey(certificate), "RS256");

            return(builder.AddSigningCredential(credential));
        }