本文整理汇总了C++中AES_set_decrypt_key函数的典型用法代码示例。如果您正苦于以下问题:C++ AES_set_decrypt_key函数的具体用法?C++ AES_set_decrypt_key怎么用?C++ AES_set_decrypt_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AES_set_decrypt_key函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CryptState_genKey
void CryptState_genKey(cryptState_t *cs) {
RAND_bytes(cs->raw_key, AES_BLOCK_SIZE);
RAND_bytes(cs->encrypt_iv, AES_BLOCK_SIZE);
RAND_bytes(cs->decrypt_iv, AES_BLOCK_SIZE);
#ifndef USE_POLARSSL
AES_set_encrypt_key(cs->raw_key, 128, &cs->encrypt_key);
AES_set_decrypt_key(cs->raw_key, 128, &cs->decrypt_key);
#else
aes_setkey_enc(&cs->aes_enc, cs->raw_key, 128);
aes_setkey_dec(&cs->aes_dec, cs->raw_key, 128);
#endif
cs->bInit = true;
}
示例2: memset
void Message::dechiffrement(const unsigned char *key){
unsigned char trame [1024];
const char *chif = this->chiffre.toStdString().c_str();
unsigned char iv[AES_BLOCK_SIZE];
memset(iv, 0x00, AES_BLOCK_SIZE);
AES_KEY dec_key;
AES_set_decrypt_key(key,256,&dec_key);
AES_cbc_encrypt((const unsigned char *)chif,trame,strlen(chif),&dec_key, iv,AES_DECRYPT);
this->msg = QString((const char *)trame);
}
示例3: main
main()
{
AES_set_encrypt_key(test_key, 128, &encks);
AES_set_decrypt_key(test_key, 128, &decks);
test_vector(vector_17, sizeof(vector_17));
test_vector(vector_31, sizeof(vector_31));
test_vector(vector_32, sizeof(vector_32));
test_vector(vector_47, sizeof(vector_47));
test_vector(vector_48, sizeof(vector_48));
test_vector(vector_64, sizeof(vector_64));
exit(0);
}
示例4: aes_decrypte
/*
* des - aes加密函数
* param - ciphertext: 密文数据
* plaintext: 解密后明文数据
* len: 密文数据长度,CBC模式以bytes为单位进行加密,该len长度有一定容错空间,解密不会出错。建议传入密文数据长度。
*
* ret - void
*/
void aes_decrypte(const u_char *ciphertext, u_char *plaintext, u_int len)
{
AES_KEY key;
unsigned char inner_iv[AES_BLOCK_SIZE * 4];
int nr_of_bits = 0;
memcpy(inner_iv, iv, sizeof(iv));
nr_of_bits = 8 * sizeof(rkey);
AES_set_decrypt_key(rkey, nr_of_bits, &key);
AES_cbc_encrypt(ciphertext, plaintext, len, &key, inner_iv, AES_DECRYPT);
}
示例5: aes_set_decrypt_key
static int aes_set_decrypt_key(struct ssh_cipher_struct *cipher, void *key,
void *IV) {
if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) {
return -1;
}
if (AES_set_decrypt_key(key,cipher->keysize,cipher->key) < 0) {
SAFE_FREE(cipher->key);
return -1;
}
}
cipher->IV=IV;
return 0;
}
示例6: encrypt_data
void encrypt_data(FILE* input_file, FILE* output_file)
{
unsigned char inbuf[80];
unsigned char outbuf[80];
unsigned char decbuf[80];
int inlen, outlen;
AES_KEY enc_key;
AES_KEY dec_key;
AES_set_encrypt_key(key, 128, &enc_key);
//while(1) {
int i;
inlen = 80;
outlen = 80;
// inlen = fread(inbuf, 1, 80, input_file);
for (i=0; i<inlen; i++) {
inbuf[i]=0;
}
printf("input data is \n");
for (i = 0; i < inlen; i++) {
printf("%c ", inbuf[i]);
}
printf("\n");
AES_encrypt(inbuf, outbuf, &enc_key);
printf("encrypted data is \n");
for (i = 0; i < inlen; i++) {
printf("%X ", outbuf[i]);
}
printf("\n");
AES_set_decrypt_key(key, 128, &dec_key);
AES_decrypt(outbuf, decbuf, &dec_key);
printf("decrypted data is \n");
for (i = 0; i < inlen; i++) {
printf("%c ", decbuf[i]);
}
printf("\n");
outlen = fwrite(outbuf, 1, inlen, output_file);
// if (outlen < AES_BLOCK_SIZE)
// {
// break;
// }
//}
}
示例7: CryptState_setKey
void CryptState_setKey(cryptState_t *cs, const unsigned char *rkey, const unsigned char *eiv, const unsigned char *div)
{
memcpy(cs->raw_key, rkey, AES_BLOCK_SIZE);
memcpy(cs->encrypt_iv, eiv, AES_BLOCK_SIZE);
memcpy(cs->decrypt_iv, div, AES_BLOCK_SIZE);
#ifndef USE_POLARSSL
AES_set_encrypt_key(cs->decrypt_iv, 128, &cs->encrypt_key);
AES_set_decrypt_key(cs->raw_key, 128, &cs->decrypt_key);
#else
aes_setkey_enc(&cs->aes_enc, cs->decrypt_iv, 128);
aes_setkey_dec(&cs->aes_dec, cs->raw_key, 128);
#endif
cs->bInit = true;
}
示例8: aes256_init
static void aes256_init(ops_crypt_t *crypt)
{
if (crypt->encrypt_key)
free(crypt->encrypt_key);
crypt->encrypt_key=malloc(sizeof(AES_KEY));
if (AES_set_encrypt_key(crypt->key,KEYBITS_AES256,crypt->encrypt_key))
fprintf(stderr,"aes256_init: Error setting encrypt_key\n");
if (crypt->decrypt_key)
free(crypt->decrypt_key);
crypt->decrypt_key=malloc(sizeof(AES_KEY));
if (AES_set_decrypt_key(crypt->key,KEYBITS_AES256,crypt->decrypt_key))
fprintf(stderr,"aes256_init: Error setting decrypt_key\n");
}
示例9: aesBlockDecrypt
guint8* aesBlockDecrypt(gchar *aesKey, gchar *aesIV, gchar *src, gint length) {
AES_KEY key;
AES_set_decrypt_key((const unsigned char *)aesKey, 128, &key);
guint8 iv[16];
memcpy(iv, aesIV, sizeof(iv));
gint aeslen = length & ~0xf;
guint8 *data = g_malloc(2048 * sizeof(guint8));
AES_cbc_encrypt((const unsigned char *)src, data, aeslen, &key, iv, AES_DECRYPT);
memcpy(data + aeslen, src + aeslen, length - aeslen);
return data;
}
示例10: switch
void svCrypto::SetAESKey(svAESCrypt mode,
const uint8_t *plain_key, AES_KEY &crypt_key)
{
switch (mode) {
case svAES_ENCRYPT:
if (AES_set_encrypt_key(plain_key, aes_key_bits, &crypt_key) != 0)
throw svExCryptoSetAESEncryptKey();
break;
case svAES_DECRYPT:
if (AES_set_decrypt_key(plain_key, aes_key_bits, &crypt_key) != 0)
throw svExCryptoSetAESDecryptKey();
break;
}
}
示例11: AES256_ige_decrypt
vector<unsigned char> AES256_ige_decrypt(vector<unsigned char> encrypted_answer,vector<unsigned char> tmp_aes_iv,vector<unsigned char> tmp_aes_key)
{
vector<unsigned char> res(encrypted_answer.size(),0);
AES_KEY key;
// vector<unsigned char> x_0(tmp_aes_iv.begin(), tmp_aes_iv.begin()+10);
// vector<unsigned char> y_0(tmp_aes_iv.begin()+10, tmp_aes_iv.end());
// tmp_aes_iv = mergeVectors(y_0, x_0);
AES_set_decrypt_key(&tmp_aes_key[0], 256, &key);
AES_ige_encrypt(&encrypted_answer[0], &res[0], encrypted_answer.size(), &key, &tmp_aes_iv[0], AES_DECRYPT);
return res;
}
示例12: decpry
int decpry(char *ibuf, int len)
{
struct sys_key *pskey = get_shm();
struct sys_key skey;
memcpy(&skey, pskey, sizeof(struct sys_key));
AES_KEY dec_key;
unsigned char dec_out[len];
memset(dec_out, 0, len);
AES_set_decrypt_key(skey.key, KEYLEN*8, &dec_key);
AES_cbc_encrypt(ibuf, dec_out, len, &dec_key, skey.iv_dec,
AES_DECRYPT);
memcpy(ibuf, dec_out, len);
return 0;
}
示例13: aesBlock
/* Encrypt or decrypt one block with AES and the given key */
static void aesBlock(unsigned char out[16], const unsigned char key[],
int keyBits, const unsigned char in[16], int dir)
{
extern void exit(int status);
int retCode;
AES_KEY aesKey;
if (dir==AES_ENCRYPT)
retCode = AES_set_encrypt_key(key, keyBits, &aesKey);
else
retCode = AES_set_decrypt_key(key, keyBits, &aesKey);
if (retCode!=0) exit(retCode); /* Not very gracefull, but still... */
if (dir==AES_ENCRYPT) AES_encrypt(in, out, &aesKey);
else AES_decrypt(in, out, &aesKey);
}
示例14: AES_KW_Decrypt
bool AES_KW_Decrypt(COSE_Enveloped * pcose, const byte * pbKeyIn, size_t cbitKey, const byte * pbCipherText, size_t cbCipherText, byte * pbKeyOut, int * pcbKeyOut, cose_errback * perr)
{
byte rgbOut[256 / 8];
AES_KEY key;
CHECK_CONDITION(AES_set_decrypt_key(pbKeyIn, (int)cbitKey, &key) == 0, COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(AES_unwrap_key(&key, NULL, rgbOut, pbCipherText, (int) cbCipherText), COSE_ERR_CRYPTO_FAIL);
memcpy(pbKeyOut, rgbOut, cbCipherText - 8);
*pcbKeyOut = (int) (cbCipherText - 8);
return true;
errorReturn:
return false;
}
示例15: main
main(){
AES_KEY AESkey;
unsigned char MBlock[16];
unsigned char MBlock2[16];
unsigned char CBlock[16];
unsigned char Key[16];
int i;
/*
* Key contains the actual 128-bit AES key. AESkey is a data structure
* holding a transformed version of the key, for efficiency.
*/
Key[0]=1;
for (i=1; i<=15; i++) {
Key[i] = 0;
}
AES_set_encrypt_key((const unsigned char *) Key, 128, &AESkey);
MBlock[0] = 1;
for (i=1; i<16; i++)
MBlock[i] = 0;
AES_encrypt((const unsigned char *) MBlock, CBlock, (const AES_KEY *) &AESkey);
for (i=0; i<16; i++)
printf("%X", CBlock[i]/16), printf("%X", CBlock[i]%16);
printf("\n");
/*
* We need to set AESkey appropriately before inverting AES.
* Note that the underlying key Key is the same; just the data structure
* AESkey is changing (for reasons of efficiency).
*/
AES_set_decrypt_key((const unsigned char *) Key, 128, &AESkey);
AES_decrypt((const unsigned char *) CBlock, MBlock2, (const AES_KEY *) &AESkey);
for (i=0; i<16; i++)
printf("%X", MBlock2[i]/16), printf("%X", MBlock2[i]%16);
printf("\n");
}