开发者

Advanced Encryption Standard Usage in C

i have this source, but im having a hard time using it http://www.hoozi.com/Articles/AESEncryption.htm i cant seem to be able to use it in my code since it encrypts the first 16 chars of it only, i was hoping that someone helps me encrypting that char *

 char *Data = NULL;
 asprintf(&开发者_运维问答amp;Data, "%s|%s", var1 /* Unknown Length */, var2);

any code sample please to encrypt Data after using asprintf?

thanks...


AES is a block encryption. It works on one block at a time. One possibility is to just call it once for each 16-byte block in your input. When you get to the end of the input, pad the last piece out to 16 bytes, and encrypt it as well. This is called "Electronic Code Book" (ECB) mode. It has the disadvantage that if there are are two (or more) blocks of input that are identical, they'll produce identical output. That being the case, ECB is only rarely recommended.

There are a number of other modes of operation that avoid that problem. My advice would be to look for another library that already implements them (e.g., I'm pretty sure beecrypt does). Unfortunately, without knowing what you're doing it's hard to say which is most suitable, but I'd start by looking at CBC and CFB on that page as a couple of reasonable possibilities.


AES encrypts in 16 byte blocks. To encrypt more than one block of data, you need to use it with one of the modes of operation. I'd recommend using CBC mode. You'll want to zero-pad your data to the 16-byte boundary as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜