Can I use AES in CTR mode in .NET?

前端 未结 5 548
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 01:45

.NET\'s AES does not implement CTR directly. It only implements CBC, CFB, CTS, ECB and OFB.

Can I use any of these modes and securely implement CTR around them, or

5条回答
  •  死守一世寂寞
    2020-12-10 01:55

    All you need to do is to use AES in ECB mode with a key (no padding, no IV) to encrypt a 128-bit counter. The plain text is then XORed with the encrypted output of the counter. For each block the counter is incremented. Encryption and decryption is the same due to the properties of the XOR operator.

    You can find an implementation (my own) for AES128 CTR mode here:

    https://gist.github.com/hanswolff/8809275

    It should be easy to use.

提交回复
热议问题