public void WhenTypeIsNull_ThrowsNotSupportedException() { _sut.Type = null; Action act = () => _sut.ToSignatureAlgorithm(_encryptionKey, _recordVersion); act.Should().Throw <NotSupportedException>(); }
public void GivenHMACDataRecord_ReturnsHMACDataRecord() { var sut = new SignatureAlgorithmDataRecordV2 { Type = "HMAC", Parameter = _encryptedKey, HashAlgorithm = HashAlgorithmName.MD5.Name, IsParameterEncrypted = true }; using (var actual = sut.ToSignatureAlgorithm(_encryptionKey, _recordVersion)) { var expected = new HMACSignatureAlgorithm(_unencryptedKey, HashAlgorithmName.MD5); actual.Should().BeAssignableTo <HMACSignatureAlgorithm>(); actual.As <HMACSignatureAlgorithm>().Should().BeEquivalentTo(expected); } }
public void GivenLegacyRecordVersion_DoesNotDecryptParameter(int?legacyVersion) { var sut = new SignatureAlgorithmDataRecordV2 { Type = "HMAC", Parameter = _unencryptedKey, HashAlgorithm = HashAlgorithmName.MD5.Name }; var actual = sut.ToSignatureAlgorithm(_encryptionKey, legacyVersion); actual.Should().BeAssignableTo <HMACSignatureAlgorithm>(); var actualKeyBytes = actual.As <HMACSignatureAlgorithm>().Key; var actualKey = Encoding.UTF8.GetString(actualKeyBytes); actualKey.Should().Be(_unencryptedKey); }
public void WhenParameterIsNotEncrypted_DoesNotDecryptParameter() { var sut = new SignatureAlgorithmDataRecordV2 { Type = "HMAC", Parameter = _unencryptedKey, HashAlgorithm = HashAlgorithmName.MD5.Name, IsParameterEncrypted = false }; var actual = sut.ToSignatureAlgorithm(_encryptionKey, _recordVersion); actual.Should().BeAssignableTo <HMACSignatureAlgorithm>(); var actualKeyBytes = actual.As <HMACSignatureAlgorithm>().Key; var actualKey = Encoding.UTF8.GetString(actualKeyBytes); actualKey.Should().Be(_unencryptedKey); }
public void GivenECDsaDataRecord_ReturnsECDsaAlgorithm() { using (var ecdsa = ECDsa.Create()) { var publicParameters = ecdsa.ExportParameters(false); var sut = new SignatureAlgorithmDataRecordV2 { Type = "ECDsa", Parameter = publicParameters.ToXml(), HashAlgorithm = HashAlgorithmName.MD5.Name, IsParameterEncrypted = false }; using (var actual = sut.ToSignatureAlgorithm(_encryptionKey, _recordVersion)) { 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()); } } }
public void GivenRSADataRecord_ReturnsRSAAlgorithm() { using (var rsa = new RSACryptoServiceProvider()) { var publicParameters = rsa.ExportParameters(false); var sut = new SignatureAlgorithmDataRecordV2 { Type = "RSA", Parameter = publicParameters.ToXml(), HashAlgorithm = HashAlgorithmName.MD5.Name, IsParameterEncrypted = false }; using (var actual = sut.ToSignatureAlgorithm(_encryptionKey, _recordVersion)) { 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()); } } }