public void Test_Decrypt_DecryptsTheCiphertext_WhenTheSameStrategyInstanceIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); Assert.Equal("Hello world", strategy.Decrypt(ciphertext)); }
public void Test_Decrypt_DecryptsTheCiphertext_WhenTheSameConfigurationIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); strategy = new AesEncryptionStrategy(strategy.KeySize, strategy.IterationCount, strategy.Salt, strategy.Iv, "password"); Assert.Equal("Hello world", strategy.Decrypt(ciphertext)); }
public void Test_Decrypt_DoesNotDecryptTheCiphertext_WhenTheIncorrectSaltIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); strategy = new AesEncryptionStrategy(strategy.KeySize, strategy.IterationCount, "133D30C2A658B3081279A97FD3B1F7CDE10C4FB61D39EEA8", strategy.Iv, "password"); try { strategy.Decrypt(ciphertext); throw new TestFailedException(); } catch (CryptographicException ce) { // this is expected } }
public void Test_Decrypt_DoesNotDecryptTheCiphertext_WhenTheIncorrectIterationCountIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); strategy = new AesEncryptionStrategy(strategy.KeySize, 2000, strategy.Salt, strategy.Iv, "password"); try { strategy.Decrypt(ciphertext); throw new TestFailedException(); } catch (CryptographicException ce) { // this is expected } }
public void test_decrypt_doesNotDecryptTheCiphertext_WhenTheIncorrectPassphraseIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); strategy = new AesEncryptionStrategy(strategy.KeySize, strategy.IterationCount, strategy.Salt, strategy.Iv, "The Wrong Password"); try { strategy.Decrypt(ciphertext); Assert.Fail(); } catch (CryptographicException ce) { // this is expected } }
public void test_decrypt_doesNotDecryptTheCiphertext_WhenTheIncorrectIvIsUsed() { strategy = new AesEncryptionStrategy(128, 1000, "password"); string ciphertext = strategy.Encrypt("Hello world"); strategy = new AesEncryptionStrategy(strategy.KeySize, strategy.IterationCount, strategy.Salt, "1DED89E4FB15F61DC6433E3BADA4A891", "password"); try { strategy.Decrypt(ciphertext); Assert.Fail(); } catch (CryptographicException ce) { // this is expected } }
public void TestAesEncryptionStrategy2(byte[] privateKey) { var strategy = new AesEncryptionStrategy(privateKey); var encryptRequest = Encoding.UTF8.GetBytes("Hello World!"); var encryptResponse = strategy.Encrypt(encryptRequest); encryptResponse.Length.Should().Be(32); // test using a new instance of the strategy strategy = new AesEncryptionStrategy(privateKey); var decryptRequest = encryptResponse; var decryptResponse = strategy.Decrypt(decryptRequest); decryptResponse.SequenceEqual(encryptRequest).Should().BeTrue(); }