extern "C"{
#include <mirdef.h>
#include <miracl.h>
};
#pragma comment(lib, "miracl.lib")
void AesTest()
{
aes _aes;
CHAR szAesKey[] = "1234567890abcdef";
CHAR szStr[32] = {"优雅人生"};
printf("密钥:%s\n明文:%s\n", szAesKey, szStr);
// 128 -- 16
// 192 -- 24
// 256 -- 32
aes_init(&_aes, MR_ECB, 16, szAesKey, NULL);
int len = aes_encrypt(&_aes, szStr);
aes_end(&_aes);
for (int i = 0; i < 16; i++)
{
printf("%X", (unsigned char)szStr[i]);
}
printf("\n");
}
// 输出:
密钥:1234567890abcdef
明文:优雅人生
517D4947C75D9E11CCA6725C53E5F65
void AesTest2()
{
aes _aes;
CHAR szAesKey[] = "1234567890abcdef";
CHAR szStr[256] = {"1234567890abcdef1234567890abcdef优雅人生www.dllhook.com"};
int key_len = 16;
printf("密钥:%s\n明文:%s\n", szAesKey, szStr);
// 128 -- 16
// 192 -- 24
// 256 -- 32
aes_init(&_aes, MR_ECB, key_len, szAesKey, NULL);
//////////////////////////////////////////////////////////////////////////
// 循环解密
int len = strlen(szStr);
int k = strlen(szStr)/key_len;
if (len%key_len > 0)
k++;
for (int n = 0; n < k; n++)
{
aes_encrypt(&_aes, &szStr[n*key_len]);
}
//////////////////////////////////////////////////////////////////////////
aes_end(&_aes);
for (int i = 0; i < sizeof(szStr); i++)
{
if (szStr[i] == 0)
break;
printf("%.2X", (unsigned char)szStr[i]);
}
printf("\n");
}
发表评论