I have two methods for encryption and decryption in CBC mode. I have all ready verified my ECB methods and they function properly. My issue is that when I test encryption in CBC with test vectors it passes them. And when I test CBC decryption with those same vectors to make sure it can go the other way, it passes those tests as well. But when I pass from encryption to decryption, I don't get the same vector back. This really doesn't make any sense to me.
public byte[,] Encrypt(byte[,] dataToEncrypt, byte[] givenKey, byte[] initializationVector)
{
//XOR the data with the IV
for (int row = 0; row < 4; row++)
{
dataToEncrypt[row,0] ^= initializationVector[4*row];
dataToEncrypt[row, 1] ^= initializationVector[(4 * row) + 1];
dataToEncrypt[row, 2] ^= initializationVector[(4 * row) + 2];
dataToEncrypt[row, 3] ^= initializationVector[(4 * row) + 3];
}
ECB encryptor = new ECB();
return encryptor.Encrypt(dataToEncrypt, givenKey);
}
public byte[,] Decrypt(byte[,] dataToDecrypt, byte[] givenKey, byte[] initializationVector)
{
ECB encryptor = new ECB();
byte[,] plainText = encryptor.Decrypt(dataToDecrypt, givenKey);
for (int row = 0; row < 4; row++)
{
plainText[row, 0] ^= initializationVector[4 * row];
plainText[row, 1] ^= initializationVector[(4 * row) + 1];
plainText[row, 2] ^= initializationVector[(4 * row) + 2];
plainText[row, 3] ^= initializationVector[(4 * row) + 3];
}
return plainText;
}
Encryptor is just my class for the AES in ECB form. So all these methods are supposed to do is take in the extra XOR's for CBC. Can anyone tell me if this seems like something is wrong?
This is for a single block of data for testing, not for large amounts of data.