Exemple #1
0
            public void WhenTypeIsNull_ThrowsNotSupportedException()
            {
                _sut.Type = null;
                Action act = () => _sut.ToSignatureAlgorithm();

                act.Should().Throw <NotSupportedException>();
            }
Exemple #2
0
            public void GivenHMACDataRecord_ReturnsHMACDataRecord()
            {
                var sut = new SignatureAlgorithmDataRecord {
                    Type          = "HMAC",
                    Parameter     = "s3cr3t",
                    HashAlgorithm = HashAlgorithmName.MD5.Name
                };

                using (var actual = sut.ToSignatureAlgorithm()) {
                    var expected = new HMACSignatureAlgorithm("s3cr3t", HashAlgorithmName.MD5);
                    actual.Should().BeAssignableTo <HMACSignatureAlgorithm>();
                    actual.As <HMACSignatureAlgorithm>().Should().BeEquivalentTo(expected);
                }
            }
Exemple #3
0
            public void GivenECDsaDataRecord_ReturnsECDsaAlgorithm()
            {
                using (var ecdsa = ECDsa.Create()) {
                    var publicParameters = ecdsa.ExportParameters(false);
                    var sut = new SignatureAlgorithmDataRecord {
                        Type          = "ECDsa",
                        Parameter     = publicParameters.ToXml(),
                        HashAlgorithm = HashAlgorithmName.MD5.Name
                    };

                    using (var actual = sut.ToSignatureAlgorithm()) {
                        var expected = ECDsaSignatureAlgorithm.CreateForVerification(HashAlgorithmName.MD5, publicParameters);
                        actual.Should().BeAssignableTo <ECDsaSignatureAlgorithm>();
                        actual.As <ECDsaSignatureAlgorithm>().Should().BeEquivalentTo(expected);
                        actual.As <ECDsaSignatureAlgorithm>().GetPublicKey().ToXml().Should().Be(publicParameters.ToXml());
                    }
                }
            }
Exemple #4
0
            public void GivenRSADataRecord_ReturnsRSAAlgorithm()
            {
                using (var rsa = new RSACryptoServiceProvider()) {
                    var publicParameters = rsa.ExportParameters(false);
                    var sut = new SignatureAlgorithmDataRecord {
                        Type          = "RSA",
                        Parameter     = publicParameters.ToXml(),
                        HashAlgorithm = HashAlgorithmName.MD5.Name
                    };

                    using (var actual = sut.ToSignatureAlgorithm()) {
                        var expected = RSASignatureAlgorithm.CreateForVerification(HashAlgorithmName.MD5, publicParameters);
                        actual.Should().BeAssignableTo <RSASignatureAlgorithm>();
                        actual.As <RSASignatureAlgorithm>().Should().BeEquivalentTo(expected);
                        actual.As <RSASignatureAlgorithm>().GetPublicKey().ToXml().Should().Be(publicParameters.ToXml());
                    }
                }
            }