• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ AES_set_decrypt_key函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中AES_set_decrypt_key函数的典型用法代码示例。如果您正苦于以下问题:C++ AES_set_decrypt_key函数的具体用法?C++ AES_set_decrypt_key怎么用?C++ AES_set_decrypt_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了AES_set_decrypt_key函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:cyberroadie,项目名称:umurmur,代码行数:13,代码来源:crypt.c


示例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);
}
开发者ID:Ektoplasma,项目名称:frontale,代码行数:13,代码来源:message.cpp


示例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);
}
开发者ID:slave5vw,项目名称:IEEE_Taggant_System,代码行数:13,代码来源:cts128.c


示例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);  
}
开发者ID:misslio,项目名称:lctools,代码行数:21,代码来源:aes_base64.c


示例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;
}
开发者ID:SHLD,项目名称:node-libssh,代码行数:14,代码来源:libcrypto.c


示例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;
//		}
	//}
}
开发者ID:jagleeso,项目名称:jiawen-opencl,代码行数:50,代码来源:cpu-aes.c


示例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;
}
开发者ID:cyberroadie,项目名称:umurmur,代码行数:14,代码来源:crypt.c


示例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");
    }
开发者ID:MrKID,项目名称:RetroShare,代码行数:14,代码来源:symmetric.c


示例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;
}
开发者ID:houzhenggang,项目名称:openwrt-ar9331,代码行数:14,代码来源:ssl.c


示例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;
	}
}
开发者ID:adzymaniac,项目名称:dingap,代码行数:15,代码来源:svcrypto.cpp


示例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;
}
开发者ID:fedochet,项目名称:SCLIC,代码行数:15,代码来源:AES.cpp


示例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;
}
开发者ID:zh-cool,项目名称:restful,代码行数:16,代码来源:encry.c


示例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);
}
开发者ID:rfjakob,项目名称:crypto1619,代码行数:17,代码来源:eme2-ref.c


示例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;
}
开发者ID:KaneRoot,项目名称:COSE-C,代码行数:16,代码来源:openssl.c


示例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");
}
开发者ID:torrencio,项目名称:elec490,代码行数:45,代码来源:example.c


示例16: aes_ecb_decrypt

static ERL_NIF_TERM aes_ecb_decrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary in, out, key;
    // key must be binary
    if(!enif_inspect_binary(env, argv[0], &key)) {
        return enif_make_badarg(env);
    }
    // key size should be 16 byte
    if(key.size != 16) {
      return enif_make_badarg(env);
    }
    // cipher must be binary
    if(!enif_inspect_binary(env, argv[1], &in)) {
      return enif_make_badarg(env);
    }
    // cipher shoule be 16 byte block
    if(in.size % 16) {
      return enif_make_badarg(env);
    }

    unsigned char* decoded = (unsigned char*)malloc(sizeof(unsigned char)*in.size);

    struct aes_key_st* decrypt_key = (struct aes_key_st*)malloc(sizeof(AES_KEY));
    memset(decrypt_key, 0, sizeof(AES_KEY));
    AES_set_decrypt_key((unsigned char*)(key.data), 128, decrypt_key);

    int i = 0;
    for(i = 0; i < in.size; i += 16) {
      AES_decrypt((unsigned char*)&in.data[i], (unsigned char*)&decoded[i], decrypt_key);
    }
    //Remove padding
    unsigned char padding = (unsigned char) decoded[in.size-1];

    if(!enif_alloc_binary(in.size - padding, &out)) {
        free(decoded);
        free(decrypt_key);
        return enif_make_badarg(env);
    }
    
    strncpy((unsigned char*)out.data, decoded, in.size - padding);

    free(decoded);
    free(decrypt_key);
    return enif_make_binary(env, &out);
}
开发者ID:Asif-Malik1,项目名称:soul,代码行数:45,代码来源:aes_nif.c


示例17: AES_Crypto

/* aes crypto function wrapper - p_text : plain text, c_text : cipher text, aes_key : from GetKey, mode : ENCRYPT/DECRYPT, size : data size */
unsigned char* AES_Crypto(unsigned char* p_text, unsigned char* c_text, char* aes_key, unsigned char* iv, int mode,  unsigned long size)
{
	AES_KEY e_key, d_key;
	
	AES_set_encrypt_key((unsigned char*)aes_key, 128, &e_key);
	AES_set_decrypt_key((unsigned char*)aes_key, 128, &d_key);
	
	if(mode == 1)
	{
		AES_cbc_encrypt(p_text, c_text, size, &e_key, iv, AES_ENCRYPT);
		return c_text;
	}
	else
	{
		AES_cbc_encrypt(c_text, p_text, size, &d_key, iv, AES_DECRYPT);
		return p_text;
	}
}
开发者ID:tizenorg,项目名称:framework.security.secure-storage,代码行数:19,代码来源:ss_server_main.c


示例18: aes_block_decrypt

static bool aes_block_decrypt(void * buffer, size_t len)
{
    AES_KEY key;
    char out[16];
    size_t bc = len / 16;
    char *cbuf = (char *)buffer;

    if(NULL == buffer || len % 16 != 0)
        return false;

    AES_set_decrypt_key((const unsigned char*)aes_ukey, 128, &key);

    for(size_t i = 0 ; i < bc ; i ++) {
        AES_decrypt((const unsigned char*)(cbuf + i * 16), (unsigned char*)out, &key);
        memcpy(cbuf + i * 16, out, 16);
    }
    return true;
}
开发者ID:hefangshi,项目名称:hack-of-zhunru,代码行数:18,代码来源:enc.cpp


示例19: My_AES_CBC_Decrypt

void  My_AES_CBC_Decrypt(u8 * key, u8 *InputMessage,  u32 InputMessageLength, u8 *OutputMessage)
{
	u8 *InBuf_ptr = InputMessage;
	AES_KEY  ass_key;
	int length_in_pad = 0;
	u8  iv[CRL_AES_BLOCK] = {0};
	int i;
	for(i = 0; i < CRL_AES_BLOCK; i++){
		iv[i] = IV[i];
	}
	
	memset(&ass_key, 0, sizeof(AES_KEY));
	if(AES_set_decrypt_key(key, 128, &ass_key) < 0){
		printf("AES_Dec set key error...\n");
		return ;
	}
	AES_cbc_encrypt(InputMessage, OutputMessage, InputMessageLength, &ass_key, iv, AES_DECRYPT);
}
开发者ID:oblivionangel,项目名称:EV_Power,代码行数:18,代码来源:AES.c


示例20: assert

//解密数据pData, 数据长度为length
bool CCryptAes::Decrypt(const unsigned char *pEncryptData, int length, unsigned char *pPlainData)
{
	assert(pPlainData != NULL);
	assert(pEncryptData != NULL);

	AES_KEY aes;
	unsigned char iv[AES_BLOCK_SIZE];
	memset(iv, 0, sizeof(iv));

	if (AES_set_decrypt_key(m_userKey, m_keyBits, &aes) < 0)
	{
		return false;
	}

	AES_cbc_encrypt(pEncryptData, pPlainData, length, &aes, iv, AES_DECRYPT);

	return true;
}
开发者ID:dulton,项目名称:proxy,代码行数:19,代码来源:CryptAes.cpp



注:本文中的AES_set_decrypt_key函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ AF函数代码示例发布时间:2022-05-30
下一篇:
C++ AES_decrypt函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap