Guest User

Untitled

a guest
Oct 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. private byte[] aesCounterCrypt(byte[] input, byte[] iv)
  2. {
  3. byte[] key = new byte[]{
  4. 0xF1, 0x7D, 0x65, 0xA8, 0x2C, 0xC5, 0x32, 0x93, 0xFC, 0x44, 0xC9,
  5. 0x36, 0xC7, 0x03, 0xD4, 0x4F, 0xCD, 0x18, 0x68, 0x81, 0x7E, 0xD4,
  6. 0xB4, 0xA3, 0xC0, 0x65, 0x87, 0xF3, 0x71, 0x1D, 0xD5, 0xB6
  7. };
  8.  
  9. byte[] output = new byte[input.Length];
  10.  
  11. var aes = new AesCryptoServiceProvider();
  12. aes.Mode = CipherMode.ECB; //The mode is actually counter, but .net doesn't have a imp for that. This'll do.
  13. aes.Padding = PaddingMode.None;
  14.  
  15. var icpt = aes.CreateDecryptor(key, iv);
  16.  
  17. for (int i = 0; i < (input.Length / 16); i++)
  18. {
  19. icpt.TransformBlock(input, i * 16, 16, output, i * 16);
  20.  
  21. //XOR the output with the plaintext producing the cipher text
  22. for (int j = 0; j < output.Length; j++)
  23. output[(i * 16) + j] = (byte)(output[j] ^ input[(i * 16) + i]);
  24.  
  25. for (int x = 0; x < 0x1f; x++)
  26. {
  27. iv[x] = (byte)((iv[x] + 1) & 0xff);
  28.  
  29. if (iv[x] != 0) break;
  30. }
  31.  
  32. //Update with new iv
  33. icpt = aes.CreateDecryptor(key, iv);
  34. }
  35.  
  36. return output;
  37. }
Add Comment
Please, Sign In to add comment