Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private byte[] aesCounterCrypt(byte[] input, byte[] iv)
- {
- byte[] key = new byte[]{
- 0xF1, 0x7D, 0x65, 0xA8, 0x2C, 0xC5, 0x32, 0x93, 0xFC, 0x44, 0xC9,
- 0x36, 0xC7, 0x03, 0xD4, 0x4F, 0xCD, 0x18, 0x68, 0x81, 0x7E, 0xD4,
- 0xB4, 0xA3, 0xC0, 0x65, 0x87, 0xF3, 0x71, 0x1D, 0xD5, 0xB6
- };
- byte[] output = new byte[input.Length];
- var aes = new AesCryptoServiceProvider();
- aes.Mode = CipherMode.ECB; //The mode is actually counter, but .net doesn't have a imp for that. This'll do.
- aes.Padding = PaddingMode.None;
- var icpt = aes.CreateDecryptor(key, iv);
- for (int i = 0; i < (input.Length / 16); i++)
- {
- icpt.TransformBlock(input, i * 16, 16, output, i * 16);
- //XOR the output with the plaintext producing the cipher text
- for (int j = 0; j < output.Length; j++)
- output[(i * 16) + j] = (byte)(output[j] ^ input[(i * 16) + i]);
- for (int x = 0; x < 0x1f; x++)
- {
- iv[x] = (byte)((iv[x] + 1) & 0xff);
- if (iv[x] != 0) break;
- }
- //Update with new iv
- icpt = aes.CreateDecryptor(key, iv);
- }
- return output;
- }
Add Comment
Please, Sign In to add comment