Beispiel #1
0
            public void WhenHashAlgorithmIsNotSupported_ThrowsNotSupportedException()
            {
                var    sut = new RSASignatureAlgorithm(new HashAlgorithmName("unsupporteed"), _rsa);
                Action act = () => sut.ComputeHash("payload");

                act.Should().Throw <NotSupportedException>();
            }
 public RSASignatureAlgorithmTests()
 {
     _rsa              = new RSACryptoServiceProvider();
     _publicKeyParams  = _rsa.ExportParameters(false);
     _privateKeyParams = _rsa.ExportParameters(true);
     _sut              = new RSASignatureAlgorithm(HashAlgorithmName.SHA1, _publicKeyParams, _privateKeyParams);
 }
Beispiel #3
0
            public void CreatesHash()
            {
                var sut     = new RSASignatureAlgorithm(HashAlgorithmName.SHA384, _rsa);
                var payload = "_abc_123_";
                var actual  = sut.ComputeHash(payload);

                actual.Should().NotBeNull().And.NotBeEmpty();
            }
Beispiel #4
0
 public RSASignatureAlgorithmTests()
 {
     _rsa              = new RSACryptoServiceProvider();
     _publicKeyParams  = _rsa.ExportParameters(false);
     _privateKeyParams = _rsa.ExportParameters(true);
     _signer           = RSASignatureAlgorithm.CreateForSigning(HashAlgorithmName.SHA1, _privateKeyParams);
     _verifier         = RSASignatureAlgorithm.CreateForVerification(HashAlgorithmName.SHA1, _publicKeyParams);
 }
            public void CanVerifyWithAlgorithmThatKnowsAboutThePrivateKey()
            {
                var payload   = "_abc_123_";
                var signature = _sut.ComputeHash(payload);
                var verifier  = new RSASignatureAlgorithm(HashAlgorithmName.SHA1, _rsa);
                var actual    = verifier.VerifySignature(payload, signature);

                actual.Should().BeTrue();
            }
Beispiel #6
0
            public void CanVerifyWithAlgorithmThatOnlyKnowsAboutThePublicKey()
            {
                var payload   = "_abc_123_";
                var signature = _signer.ComputeHash(payload);
                var verifier  = RSASignatureAlgorithm.CreateForVerification(HashAlgorithmName.SHA1, _publicKeyParams);
                var actual    = verifier.VerifySignature(payload, signature);

                actual.Should().BeTrue();
            }
 public static ISignatureAlgorithm CreateForSigning(RSAParameters privateParameters, HashAlgorithmName hashAlgorithm)
 {
     return(RSASignatureAlgorithm.CreateForSigning(hashAlgorithm, privateParameters));
 }
 public static ISignatureAlgorithm CreateForVerification(RSAParameters publicParameters, HashAlgorithmName hashAlgorithm)
 {
     return(RSASignatureAlgorithm.CreateForVerification(hashAlgorithm, publicParameters));
 }