本文整理汇总了C++中AES::makeKey方法的典型用法代码示例。如果您正苦于以下问题:C++ AES::makeKey方法的具体用法?C++ AES::makeKey怎么用?C++ AES::makeKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AES
的用法示例。
在下文中一共展示了AES::makeKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
if(argc < 3) {
printf("USAGE: aes KEY PLAINTEXT\n");
return 1;
}
byte *key;
uint *ct, *pt;
uint keySize = stringToByteArray(argv[1], &key);
uint ptSize = stringToByteArray(argv[2], &pt);
if(keySize != 16 && keySize != 24 && keySize != 32) {
printf("Invalid AES key size.\n");
return 1;
}
if(ptSize % 4 != 0) {
printf("Plaintext size must be a multiple of AES block size.\n");
return 1;
}
ct = (uint *)malloc(ptSize*sizeof(uint));
AES *aes = new AES();
aes->makeKey(key, keySize << 3, DIR_ENCRYPT);
for(uint i = 0; i < ptSize; i += 4) {
aes->encrypt(pt + i, ct + i);
}
printHexArray(ct, ptSize);
return 0;
}
示例2: main
int main(int argc, char **argv) {
if(argc < 2) {
printf("USAGE: benchmark FILE\n");
return 1;
}
byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint keySize = 16;
uint *ct, *pt;
FILE *f = fopen(argv[1], "rb");
if(f == NULL) {
printf("File not found.\n");
return 1;
}
fseek(f, 0, SEEK_END);
uint f_size = ftell(f);
rewind(f);
if(f_size % 4*sizeof(uint) != 0) {
printf("Plaintext size must be a multiple of AES block size.\n");
return 1;
}
uint ptSize = f_size / sizeof(uint);
pt = (uint*)malloc(f_size);
fread(pt, sizeof(uint), ptSize, f);
fclose(f);
ct = (uint *)malloc(ptSize*sizeof(uint));
AES *aes = new AES();
aes->makeKey(key, keySize << 3, DIR_ENCRYPT);
clock_t start = clock();
for(uint i = 0; i < ptSize; i += 4) {
aes->encrypt(pt + i, ct + i);
}
clock_t end = clock();
printf("%d blocks encrypted in %d/%d seconds.\n", ptSize >> 2, end-start, CLOCKS_PER_SEC);
return 0;
}