能力值:
( LV6,RANK:90 )
|
-
-
3 楼
这个我用过,参考下
#define AES_BLOCK_SIZE 16
unsigned char rkey[16] =
{
0x20,0x66,0x5F,0x65,0x72,0x72,0x3B,0x0D,0x0A,0x09,0x09,0x09,0x7D,0x0D,0x0A,0x09
};
unsigned char saved_iv[AES_BLOCK_SIZE * 6] =
{
0x09,0x65,0x6C,0x73,0x65,0x0D,0x0A,0x23,0x65,0x6E,0x64,0x69,0x66,0x0D,0x0A,0x09,\
0x09,0x69,0x66,0x20,0x28,0x61,0x6C,0x67,0x5F,0x6B,0x20,0x26,0x20,0x53,0x53,0x4C,\
0x5F,0x6B,0x47,0x4F,0x53,0x54,0x29,0x20,0x0D,0x0A,0x09,0x09,0x09,0x7B,0x0D,0x0A,\
0x09,0x09,0x09,0x69,0x6E,0x74,0x20,0x72,0x65,0x74,0x20,0x3D,0x20,0x30,0x3B,0x0D,\
0x0A,0x09,0x09,0x09,0x45,0x56,0x50,0x5F,0x50,0x4B,0x45,0x59,0x5F,0x43,0x54,0x58,\
0x20,0x2A,0x70,0x6B,0x65,0x79,0x5F,0x63,0x74,0x78,0x3B,0x0D,0x0A,0x09,0x09,0x09
};
void AES_6Block_Encrypt(unsigned char *plaintext,unsigned char *ciphertext)
{
AES_KEY key;
unsigned char iv[AES_BLOCK_SIZE * 6];
int nr_of_bits = 0;
int nr_of_bytes = 0;
memset(plaintext, 0, AES_BLOCK_SIZE * 6);
memset(ciphertext, 0, AES_BLOCK_SIZE * 6);
memcpy(iv, saved_iv, sizeof(iv));
nr_of_bits = 8 * sizeof(rkey);
AES_set_encrypt_key(rkey, nr_of_bits, &key);
nr_of_bytes = sizeof(plaintext);
return AES_cbc_encrypt(plaintext,ciphertext,nr_of_bytes,&key,iv,AES_ENCRYPT);
}
|
能力值:
( LV7,RANK:100 )
|
-
-
5 楼
[QUOTE=skypismire;1005275]这个我用过,参考下
#define AES_BLOCK_SIZE 16
unsigned char rkey[16] =
{
0x20,0x66,0x5F,0x65,0x72,0x72,0x3B,0x0D,0x0A,0x09,0x09,0x09,0x7D,0x0D,0x0A,0x09
};
...[/QUOTE]
plaintext是需要加解密的明文吗?
第2个和第5个参数是什么意思呢?
最后一个参数是常量吧?我这边用的delphi所以没有
aes_encrypt和aes_decrypt的常量值是多少呢?
|
能力值:
( LV6,RANK:90 )
|
-
-
6 楼
AES_cbc_encrypt(plaintext,ciphertext,nr_of_bytes,&key,iv,AES_ENCRYPT);
plaintext:明文
ciphertext:加(解)密后的密文
iv:初始向量,这跟你选择的模式有关,有ecb,cbc,cfb,ofb,ctr模式,你可以看看<<密码学与网络安全>>第八章
AES_ENCRYPT:表明是加密,常量
|