public void Encrypt_Ecb_ReturnsVector(byte[] keyBytes, byte[] clearBytes, byte[] cipherBytes) { //arrange var sut = new BlowfishEncryptor(BlowfishCipherMode.Ecb); var expected = cipherBytes; //act var actual = sut.Encrypt(clearBytes, keyBytes); //assert Assert.That(actual, Is.EqualTo(expected)); }
public void Decrypt_Ecb_WhenDecryptedWithEncryptionKey_returnsInput(byte[] input, byte[] key) { //Arrange var sut = new BlowfishEncryptor(BlowfishCipherMode.Ecb); var encrypted = sut.Encrypt(input, key); //Act var output = sut.Decrypt(encrypted, key); //Assert Assert.IsTrue(input.SequenceEqual(output)); }
public async Task Encrypt_Ecb_ReturnsVector(byte[] keyBytes, byte[] clearBytes, byte[] cipherBytes) { // Arrange var sut = new BlowfishEncryptor(BlowfishCipherMode.Ecb, PaddingMode.None); var expected = cipherBytes; // Act var actual = await sut.EncryptAsync(clearBytes, keyBytes); // Assert Assert.That(actual, Is.EqualTo(expected)); }
public async Task Decrypt_Cbc_WhenDecryptedWithEncryptionKey_returnsInput(byte[] input, byte[] key) { // Arrange var sut = new BlowfishEncryptor(BlowfishCipherMode.Cbc); var encrypted = await sut.EncryptAsync(input, key); // Act var output = await sut.DecryptAsync(encrypted, key); // Assert Assert.IsTrue(input.SequenceEqual(output)); }
public async Task Encrypt_DifferentDataSizes_CanDecrypt(int dataSize, BlowfishCipherMode cipherMode) // a.k.a. padding works { // Arrange var expected = FastRandom.StaticInstance.GetBytes(dataSize); var sut = new BlowfishEncryptor(cipherMode, PaddingMode.PKCS7); var key = new byte[sut.MinKeySizeInBits]; // Act var encrypted = await sut.EncryptAsync(expected, key); var actual = await sut.DecryptAsync(encrypted, key); // Assert Assert.That(actual, Is.EqualTo(expected)); }