示例#1
0
 private byte[] ComputeSignature(IRequest request, RSA signingAlgorithm)
 {
     return(signingAlgorithm.SignData(
                NormalizeMsg(request),
                SigningAlgorithmConverter.ToHashAlgorithmName(SignatureAlgorithm),
                RSASignaturePadding.Pkcs1));
 }
示例#2
0
        public void VerifySignature(IRequest request, X509Certificate2 signingCertificate)
        {
            if (request == null || signingCertificate == null)
            {
                throw new AuthException(Resources.VerifySignature_Expects_NonNull_RequestAndCertificate);
            }

            using (var publicKey = signingCertificate.GetRSAPublicKey()) {
                if (!publicKey.VerifyData(
                        NormalizeMsg(request),
                        Signature,
                        SigningAlgorithmConverter.ToHashAlgorithmName(SignatureAlgorithm),
                        RSASignaturePadding.Pkcs1))
                {
                    throw new AuthException(Resources.Verify_Signature_Failed);
                }
            }
        }
示例#3
0
 private HashAlgorithm CreateHashAlgorithm()
 {
     if (SignatureAlgorithm == SigningAlgorithm.RSA_SHA256)
     {
         return(SHA256.Create());
     }
     if (SignatureAlgorithm == SigningAlgorithm.RSA_SHA384)
     {
         return(SHA384.Create());
     }
     if (SignatureAlgorithm == SigningAlgorithm.RSA_SHA512)
     {
         return(SHA512.Create());
     }
     throw new AuthenticationException(
               string.Format(
                   Resources.Hash_Algorithm_Not_Supported,
                   SigningAlgorithmConverter.ToHashAlgorithmName(SignatureAlgorithm)));
 }