public byte[] Decrypt(byte[] chiphertext) { byte[] res = new byte[chiphertext.Length]; int currpos = 0; byte[] pi = new byte[BLOCK_SIZE]; //P(i) byte[] ci = new byte[BLOCK_SIZE]; //C(i) byte[] oi = new byte[BLOCK_SIZE]; //O(i) byte[] oim = new byte[BLOCK_SIZE]; //O(i-1) Array.Copy(iv, 0, oim, 0, BLOCK_SIZE); while (currpos < chiphertext.Length) { Array.Copy(chiphertext, currpos, ci, 0, BLOCK_SIZE); oi = aes.Encrypt(oim); Array.Copy(oi, 0, oim, 0, BLOCK_SIZE); arrXOR(ci, oi); Array.Copy(ci, 0, res, currpos, BLOCK_SIZE); currpos += BLOCK_SIZE; } return(res); }
public byte[] Decrypt(byte[] chiphertext) { byte[] res = new byte[chiphertext.Length]; int currpos = 0; byte[] pi = new byte[BLOCK_SIZE]; //P(i) byte[] ci = new byte[BLOCK_SIZE]; //C(i) byte[] ctr = new byte[BLOCK_SIZE]; Array.Copy(iv, 0, ctr, 0, BLOCK_SIZE); while (currpos < chiphertext.Length) { Array.Copy(chiphertext, currpos, ci, 0, BLOCK_SIZE); pi = aes.Encrypt(ctr); arrXOR(pi, ci); Array.Copy(pi, 0, res, currpos, BLOCK_SIZE); currpos += BLOCK_SIZE; IncrCTR(ctr); } return(res); }
public byte[] Encrypt(byte[] plaintext) { byte[] res = new byte[plaintext.Length]; int currpos = 0; byte[] inpBlock = new byte[BLOCK_SIZE]; byte[] outpBlock = new byte[BLOCK_SIZE]; while (currpos < plaintext.Length) { Array.Copy(plaintext, currpos, inpBlock, 0, BLOCK_SIZE); outpBlock = aes.Encrypt(inpBlock); Array.Copy(outpBlock, 0, res, currpos, BLOCK_SIZE); currpos += BLOCK_SIZE; } return(res); }