#include <unistd.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/reboot.h>
#include "openssl/aes.h"
void main(void)
{
unsigned char src[16] = {0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x02,0x03,0x04,0x05,0x06,0x04,0x04,0x04,0x04};
const unsigned char key[16] = {48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,0};
unsigned char Des[16];
unsigned char MiWen[16] = {0x3C,0x46,0xC8,0x8E,0x98,0xC4,0x58,0xE0,0x02,0x7C,0x4D,0xD6,0xEB,0x9A,0xE0,0x1E};
unsigned char Des2[16];
//将明文进行加密
AES_KEY aeskey;
//设置密文加密的key
AES_set_encrypt_key(key,128,&aeskey);
AES_encrypt(src,Des,&aeskey);
for(int i = 0; i < 16; i++)
{
printf("%02X, ", Des[i]); //打印输出密文
}
printf("\r\n");
//设置密文解密的key
AES_set_decrypt_key(key,128,&aeskey);
AES_decrypt(Des,Des2,&aeskey);
for(int i = 0; i < 16; i++)
{
printf("%02X, ", Des2[i]);//打印输出明文
}
printf("\r\n");
//测试别人家的一个示例密文
AES_set_decrypt_key(key,128,&aeskey);
AES_decrypt(MiWen,Des2,&aeskey);
for(int i = 0; i < 16; i++)
{
printf("%02X, ", Des2[i]);//打印输出明文
}
printf("\r\n");
while(1);
}
输出结果如下:
明文加密再解密,看起来没问题。。