AES encryption for 16 bytes
I'm trying to encrypt a file using the implementation I found here:
http://msdn.microsoft.com/en-us/magazine/cc164055.aspx This implementation encrypts only 16 bytes, so my question is: Can I just use this on my whole file 16 bytes at a time? would it weaken the encryption?Use the built-in AES functions instead: AesCryptoServiceProvider.
Here's an example of how to use it to encrypt a file.
Avoid writing your own cryptography routines whenever possible-- the library versions are likely to be both better optimized and more secure than alternatives.
AES is a block cipher with a block size of 128 bits; that's why it encrypts 16 bytes at a time.
Block ciphers can be used in various modes. If you encrypt each group of 16 bytes separately and independently, you're using the cipher in ECB mode, which is the weakest mode because it doesn't hide patterns in the plaintext. It'd be better to encrypt your file in a mode that produces different ciphertext for multiple occurrences of the same plaintext, such as CBC mode, so that patterns in the plaintext don't translate into patterns in the ciphertext.
精彩评论