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_Ecb_WhenDecryptedWithEncryptionKey_returnsInput(byte[] input, byte[] key) { // Arrange var sut = new BlowfishEncryptor(BlowfishCipherMode.Ecb); 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)); }