public void Decrypt_Should_ThrowException_When_RSAPublicKeyIsProvided() { // Arrange var e1 = new ASymmetricEncryption(_publicKey); // Act & Assert Assert.Throws <InvalidOperationException>( () => { var encrypted = e1.Decrypt(_targetData); }); }
public void Decrypt_Should_ThrowException_When_NoEncryptedDataProvided() { // Arrange var e2 = new ASymmetricEncryption(_privateKey); var encrypted = new EncryptionData(); // Act & Assert Assert.Throws <ArgumentException>(() => { var decrypted = e2.Decrypt(encrypted); }); }
public void Decrypt_Should_ReturnExpectedResult_When_ProvidedCorrectPrivateKey() { // Arrange var e1 = new ASymmetricEncryption(_publicKey); var e2 = new ASymmetricEncryption(_privateKey); // Act var encrypted = e1.Encrypt(_targetData); var decrypted = e2.Decrypt(encrypted); // Assert Assert.True(_targetData.Text == decrypted.Text); }
public void Decrypt_Should_ThrowException_When_RSAPublicKeyIsProvided_When_UsingStream() { // Arrange var e1 = new ASymmetricEncryption(_publicKey); EncryptionData encrypted; // Act & Assert Assert.Throws <InvalidOperationException>( () => { using (var sr = new StreamReader($"{_assemblyPath}sample.doc")) { encrypted = e1.Decrypt(sr.BaseStream); } }); }
public void Decrypt_Should_ThrowException_When_ProvidedWrongPrivateKey() { // Arrange var wrongKey = RsaPrivateKey.LoadFromCertificateFile( $"{_assemblyPath}ASymmetricEncryptionWrong.pfx", "password"); var e1 = new ASymmetricEncryption(_publicKey); var e2 = new ASymmetricEncryption(wrongKey); var encrypted = e1.Encrypt(_targetData); // Act & Assert Assert.Throws <CryptographicException>(() => { var decrypted = e2.Decrypt(encrypted); }); }
public void Decrypt_Should_ReturnExpectedResult_When_ProvidedCorrectPrivateKeyAndUsingStream() { // Arrange var e1 = new ASymmetricEncryption(_publicKey); var e2 = new ASymmetricEncryption(_privateKey); // Act var encrypted = e1.Encrypt(_targetData); EncryptionData decrypted; using (var stream = new MemoryStream(encrypted.Bytes)) { decrypted = e2.Decrypt(stream); } // Assert Assert.True(_targetData.Text == decrypted.Text); }