当前位置: 首页>>代码示例>>C++>>正文


C++ AES_set_decrypt_key函数代码示例

本文整理汇总了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;
}
开发者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


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