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

C++ AES_cbc_encrypt函数代码示例

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

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



在下文中一共展示了AES_cbc_encrypt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: while

uint8_t *aos_cipher_decrypt(struct aos_encryption *enc, const uint8_t *in, unsigned int length)
{
	uint8_t *decrypted;
	unsigned int done = 0;
	
	decrypted = (uint8_t *)malloc(length);
	if(!decrypted)
		return NULL;
	
	while(done < length) {
		uint8_t iv[AES_BLOCK_SIZE];
		uint8_t data[AES_BLOCK_SIZE];
		struct aos_block *block = (struct aos_block *)&data;
		
		memcpy(iv, enc->iv, AES_BLOCK_SIZE);
		
		AES_cbc_encrypt(&in[done], data, AES_BLOCK_SIZE, &enc->key, iv, AES_DECRYPT);
		memcpy(&decrypted[done], &data, AES_BLOCK_SIZE);
		done += AES_BLOCK_SIZE;
		
		AES_cbc_encrypt(&in[done], &decrypted[done], block->length-AES_BLOCK_SIZE, &enc->key, iv, AES_DECRYPT);
		done += block->length-AES_BLOCK_SIZE;
	}
	
	return decrypted;
}
开发者ID:kenrestivo,项目名称:aos-tools,代码行数:26,代码来源:crypto.c


示例2: blockchain_decrypt

static int blockchain_decrypt(unsigned char *derived_key, unsigned char *data)
{
	unsigned char out[SAFETY_FACTOR];
	AES_KEY akey;
	unsigned char iv[16];
	memcpy(iv, cur_salt->data, 16);

	if(AES_set_decrypt_key(derived_key, 256, &akey) < 0) {
		fprintf(stderr, "AES_set_decrypt_key failed in crypt!\n");
	}
	AES_cbc_encrypt(data + 16, out, 16, &akey, iv, AES_DECRYPT);
	/* various tests */
	if (out[0] != '{') // fast test
		return -1;

	// "guid" will be found in the first block
	if (memmem(out, 16, "\"guid\"", 6)) {
		memcpy(iv, cur_salt->data, 16); //IV has to be reset.
		AES_cbc_encrypt(data + 16, out, SAFETY_FACTOR, &akey, iv, AES_DECRYPT);
		if (memmem(out, SAFETY_FACTOR, "\"sharedKey\"", 11) &&
			memmem(out, SAFETY_FACTOR, "\"options\"", 9))
			// Note, we 'could' check that the guid and sharedKey values are
			// 'valid' GUID's, but there really is no point. We already have
			// 2^216 confidence in the simple text strings being found.
			return 0;
	}
	return -1;
}
开发者ID:Allen-smith,项目名称:ctf-tools,代码行数:28,代码来源:blockchain_fmt_plug.c


示例3: aes_encrypt

int aes_encrypt(void *in, size_t len, unsigned char **out, unsigned char *iv, unsigned char *key)
{
    AES_KEY aeskey;
    int ret;

    if (!len)
        return 0;

    ret = AES_set_encrypt_key(key, 256, &aeskey);
    assert(!ret);

    printf("(len: %ld pad: %ld)\n", len, len % 16);
    len += len % 16;

    *out = calloc(1, len); // consider padding..
    assert(*out);

#ifdef SKIP_LAST_WORD
    AES_cbc_encrypt(in, *out, len-4, &aeskey, iv, AES_ENCRYPT); 
    memcpy(*out + (len - 4), in + (len - 4), 4);
#else
    AES_cbc_encrypt(in, *out, len, &aeskey, iv, AES_ENCRYPT); 
#endif

    printf("\nplaintext (excerpt):\n");
    print_hex(in, 128, 0);

    printf("ciphertext (excerpt):\n");
    print_hex(*out, 128, 0);

    return 0;
}
开发者ID:YtnbFirewings,项目名称:kcache,代码行数:32,代码来源:crypto.c


示例4: main

// main entrypoint
int main(int argc, char **argv)
{
    int keylength;
    printf("Give a key length [only 128 or 192 or 256!]:\n");
    scanf("%d", &keylength);

    /* generate a key with a given length */
    unsigned char aes_key[keylength/8];
    memset(aes_key, 0, keylength/8);
    if (!RAND_bytes(aes_key, keylength/8))
        exit(-1);

    /* input struct creation */
    size_t inputslength = sizeof(USR_TICKET);
    USR_TICKET ticket;
    ticket.ticketId = 1;
    time_t now = time(NULL);
    strftime(ticket.date, 20, "%Y-%m-%d", localtime(&now));
    strcpy(ticket.username, "Hello AES");

    printf("Username - %s\n", ticket.username);
    printf("Ticket Id - %d\n", ticket.ticketId);
    printf("Date - %s\n", ticket.date);

    /* init vector */
    unsigned char iv_enc[AES_BLOCK_SIZE], iv_dec[AES_BLOCK_SIZE];
    RAND_bytes(iv_enc, AES_BLOCK_SIZE);
    memcpy(iv_dec, iv_enc, AES_BLOCK_SIZE);

    // buffers for encryption and decryption
    const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
    unsigned char enc_out[encslength];
    unsigned char dec_out[inputslength];
    memset(enc_out, 0, sizeof(enc_out));
    memset(dec_out, 0, sizeof(dec_out));

    // so i can do with this aes-cbc-128 aes-cbc-192 aes-cbc-256
    AES_KEY enc_key, dec_key;
    AES_set_encrypt_key(aes_key, keylength, &enc_key);
    AES_cbc_encrypt((unsigned char *)&ticket, enc_out, encslength, &enc_key, iv_enc, AES_ENCRYPT);

    AES_set_decrypt_key(aes_key, keylength, &dec_key);
    AES_cbc_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT);

    printf("original:\t");
    hex_print((unsigned char *)&ticket, inputslength);

    printf("encrypt:\t");
    hex_print(enc_out, sizeof(enc_out));

    printf("decrypt:\t");
    hex_print(dec_out, sizeof(dec_out));

    USR_TICKET * dyc = (USR_TICKET *)dec_out;
    printf("Username - %s\n", dyc->username);
    printf("Ticket Id - %d\n", dyc->ticketId);
    printf("Date - %s\n", dyc->date);
    return 0;
}
开发者ID:HaykGrig,项目名称:My-C-Projects,代码行数:60,代码来源:main.c


示例5: akcdecrypt

static int akcdecrypt(unsigned char *derived_key, unsigned char *data)
{
	unsigned char out[CTLEN];
	int pad, n, i, key_size;
	AES_KEY akey;
	unsigned char iv[16];
	memcpy(iv, data + CTLEN - 32, 16);

	if(AES_set_decrypt_key(derived_key, 128, &akey) < 0) {
		fprintf(stderr, "AES_set_decrypt_key failed in crypt!\n");
	}
	AES_cbc_encrypt(data + CTLEN - 16, out + CTLEN - 16, 16, &akey, iv, AES_DECRYPT);

	// now check padding
	pad = out[CTLEN - 1];
	if(pad < 1 || pad > 16) /* AES block size is 128 bits = 16 bytes */
		// "Bad padding byte. You probably have a wrong password"
		return -1;
	n = CTLEN - pad;
	key_size = n / 8;
	if(key_size != 128 && key_size != 192 && key_size != 256)
		// "invalid key size"
		return -1;
	for(i = n; i < CTLEN; i++)
		if(out[i] != pad)
			// "Bad padding. You probably have a wrong password"
			return -1;
	return 0;
}
开发者ID:Allen-smith,项目名称:ctf-tools,代码行数:29,代码来源:opencl_agilekeychain_fmt_plug.c


示例6: decrypt

			void decrypt(AES_KEY &ctx, decrypt_output_type &dst, const decrypt_input_type &src, iv_type &iv)
			{
				// 16 블록(bytes)의 배수가 아닐경우 예외, 패딩을 사용할 것.
				if (0 != src.size() % 16) throw salm::exception("block size should be a fixed multiple", salm::INVALID_BAD_MULTIPLE);

				AES_cbc_encrypt(&src[0], &dst[0], src.size(), &ctx, &iv[0], AES_DECRYPT);
			}
开发者ID:JaewookYim,项目名称:salm,代码行数:7,代码来源:aes.hpp


示例7: class_AES_decrypt_with_padding

/*
 * class_AES_decrypt:
 * decrypt IN of LEN bytes
 * into a newly malloc'ed buffer
 * that is returned in OUT of OUT_LEN bytes long
 * using DEC_KEY.
 *
 * It is the *caller*'s job to free(out).
 * In and out lengths will always be different because of manditory padding.
 */
void class_AES_decrypt_with_padding(unsigned char *in, int len, unsigned char **out, int *out_len, AES_KEY *dec_key)
{
	unsigned char ivec[AES_KEY_LENGTH_IN_BITS/8];
	/*
	 * Don't use a 0 IV in the real world,
	 * see http://en.wikipedia.org/wiki/Initialization_vector for why. 
	 * Fortunately class projects are not the real world.
	 */
	memset(ivec, 0, sizeof(ivec));

	*out = (unsigned char *)malloc(len);
	assert(*out);

	AES_cbc_encrypt(in, *out, len, dec_key, ivec, AES_DECRYPT);

	/*
	 * Now undo padding.
	 */
	int padding_used = (int)(*out)[len-1];
	assert(padding_used > 0 && padding_used <= AES_KEY_LENGTH_IN_CHARS); /* or corrupted data */
	*out_len = len - padding_used;
	/*
	 * We actually return a malloc'ed buffer that is longer
	 * then out_len, but the memory system takes care of that for us. 
	 */

}
开发者ID:rmayur,项目名称:TORUpload,代码行数:37,代码来源:aes_jh.c


示例8: memset

//aes解密
unsigned char *utDecryptAes(unsigned char *in,unsigned char *pKey)
{
	 static unsigned char out[2560];
	 unsigned char caKey[2560];
   unsigned char ivec[2560],data[2048];
   long iReturn;
 //  printf("lCount=%d\n",lCount);
	memset(out,0,sizeof(out));

	 AES_KEY *key;
   key=(AES_KEY *)malloc(sizeof(AES_KEY));
	 iReturn=AES_set_decrypt_key(pKey,256,key);
   if(iReturn!=0){
   	free(key);
   	return &out[0];
   }
    memset(ivec,0,sizeof(ivec));
    memset(data,0,sizeof(data));
   iReturn=pasStrCvtHex2Bin(in,data); 
      
 //   printf("iReturnlen=%d\n",iReturn);
    if(iReturn<16){
    	free(key);
    	return &out[0];
    }
    memcpy(ivec,data,16);
   
    AES_cbc_encrypt(data+16, out,iReturn-16, key,ivec,AES_DECRYPT);
   
    free(key);
//    utStrReplaceWith(out,"\x05","\0");
    return &out[0];
}   
开发者ID:pennwin2014,项目名称:ict_school,代码行数:34,代码来源:proauth_sendata.c


示例9: decrypt

void decrypt(char *data,int round_len)
{
	char *out=malloc(sizeof(char)*round_len);

	int key_len=16;

	memset(out, 0, round_len);
	//memset(buf, 0, round_len);
	//memcpy (buf, in, len );

	unsigned char IV[key_len];
	unsigned char key[key_len];

	MD5((const unsigned char*)key_text, strlen(key_text),(unsigned char *)key);
	MD5((const unsigned char*)iv_text, strlen(iv_text),(unsigned char *)IV);

	AES_KEY aeskey;

	AES_set_decrypt_key(key, key_len*8, &aeskey);
	AES_cbc_encrypt(data,out, round_len, &aeskey, IV, AES_DECRYPT);

	memcpy (data, out, round_len );
	//printf("decrypted: '%s'\n",data);
	free(out);


}
开发者ID:roderickmackenzie,项目名称:simpleclustercode,代码行数:27,代码来源:encrypt.c


示例10: size

/**
  Performs AES decryption on a data buffer of the specified size in CBC mode.

  This function performs AES decryption on data buffer pointed by Input, of specified
  size of InputSize, in CBC mode.
  InputSize must be multiple of block size (16 bytes). This function does not perform
  padding. Caller must perform padding, if necessary, to ensure valid input data size.
  Initialization vector should be one block size (16 bytes).
  AesContext should be already correctly initialized by AesInit(). Behavior with
  invalid AES context is undefined.

  If AesContext is NULL, then return FALSE.
  If Input is NULL, then return FALSE.
  If InputSize is not multiple of block size (16 bytes), then return FALSE.
  If Ivec is NULL, then return FALSE.
  If Output is NULL, then return FALSE.

  @param[in]   AesContext  Pointer to the AES context.
  @param[in]   Input       Pointer to the buffer containing the data to be encrypted.
  @param[in]   InputSize   Size of the Input buffer in bytes.
  @param[in]   Ivec        Pointer to initialization vector.
  @param[out]  Output      Pointer to a buffer that receives the AES encryption output.

  @retval TRUE   AES decryption succeeded.
  @retval FALSE  AES decryption failed.

**/
BOOLEAN
EFIAPI
AesCbcDecrypt (
  IN   VOID         *AesContext,
  IN   CONST UINT8  *Input,
  IN   UINTN        InputSize,
  IN   CONST UINT8  *Ivec,
  OUT  UINT8        *Output
  )
{
  AES_KEY  *AesKey;
  UINT8    IvecBuffer[AES_BLOCK_SIZE];

  //
  // Check input parameters.
  //
  if (AesContext == NULL || Input == NULL || (InputSize % AES_BLOCK_SIZE) != 0) {
    return FALSE;
  }

  if (Ivec == NULL || Output == NULL || InputSize > INT_MAX) {
    return FALSE;
  }

  AesKey = (AES_KEY *) AesContext;
  CopyMem (IvecBuffer, Ivec, AES_BLOCK_SIZE);

  //
  // Perform AES data decryption with CBC mode
  //
  AES_cbc_encrypt (Input, Output, (UINT32) InputSize, AesKey + 1, IvecBuffer, AES_DECRYPT);

  return TRUE;
}
开发者ID:bhanug,项目名称:virtualbox,代码行数:61,代码来源:CryptAes.c


示例11: OpcUa_P_OpenSSL_AES_CBC_Encrypt

/*============================================================================
 * OpcUa_P_OpenSSL_AES_CBC_Encrypt
 *===========================================================================*/
OpcUa_StatusCode OpcUa_P_OpenSSL_AES_CBC_Encrypt(
    OpcUa_CryptoProvider*   a_pProvider,
    OpcUa_Byte*             a_pPlainText,
    OpcUa_UInt32            a_plainTextLen,
    OpcUa_Key*              a_key,
    OpcUa_Byte*             a_pInitalVector,
    OpcUa_Byte*             a_pCipherText,
    OpcUa_UInt32*           a_pCipherTextLen)
{
    AES_KEY         key;

    OpcUa_Byte      pInitalVector[16];

    OpcUa_InitializeStatus(OpcUa_Module_P_OpenSSL, "AES_CBC_Encrypt");

    OpcUa_ReferenceParameter(a_pProvider);

    OpcUa_ReturnErrorIfArgumentNull(a_pPlainText);
    OpcUa_ReturnErrorIfArgumentNull(a_key);
    OpcUa_ReturnErrorIfArgumentNull(a_key->Key.Data);
    OpcUa_ReturnErrorIfArgumentNull(a_pInitalVector);
    OpcUa_ReturnErrorIfArgumentNull(a_pCipherTextLen);

    if(a_plainTextLen % 16 != 0)
    {
        uStatus = OpcUa_BadInvalidArgument;
        OpcUa_GotoErrorIfBad(uStatus);
    }

    *a_pCipherTextLen = a_plainTextLen;

    /* if just the output length is needed for the caller of this function */
    if(a_pCipherText == OpcUa_Null)
    {
        OpcUa_ReturnStatusCode;
    }

    /* we have to pass the key length in bits instead of bytes */
    if(AES_set_encrypt_key(a_key->Key.Data, a_key->Key.Length * 8, &key) < 0)
    {
        uStatus = OpcUa_Bad;
        OpcUa_GotoErrorIfBad(uStatus);
    }

    /* copy the IV because the AES_cbc_encrypt function overwrites it. */
    OpcUa_P_Memory_MemCpy(pInitalVector, 16, a_pInitalVector, 16);

    /* encrypt data */
    AES_cbc_encrypt(    a_pPlainText,
                        a_pCipherText,
                        a_plainTextLen,
                        &key,
                        pInitalVector,
                        AES_ENCRYPT);

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;

OpcUa_FinishErrorHandling;
}
开发者ID:OPCFoundation,项目名称:UA-AnsiC,代码行数:63,代码来源:opcua_p_openssl_aes.c


示例12: htc_aes_encrypt_chunk

int htc_aes_encrypt_chunk(char *buf, int size, char *key, char *iv)
{
    AES_KEY enc_key;

    AES_set_encrypt_key(key, 8*HTC_AES_KEYSIZE, &enc_key);
    AES_cbc_encrypt(buf, buf, size, &enc_key, iv, AES_ENCRYPT);
}
开发者ID:0x2b,项目名称:ruuveal,代码行数:7,代码来源:htcaes.c


示例13: fprintf

/* AES解密 */
char *aes_dec(char *pawd, int is_print) {
    char *plain = "[email protected]";
    unsigned char iv[AES_BLOCK_SIZE] = {0};
    unsigned char *input;
    int len;
    AES_KEY key;

    /* 设置密钥 */
    if (AES_set_decrypt_key((const unsigned char *)plain, LEN_128, &key) < 0) {
        fprintf(stderr, "Unable to set encryption key in AES\n");
    }

    /* 待加密数据长度 */
    len = strlen(pawd);

    /* 态度分配明文串 */
    input = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *string = (char *)calloc(len, sizeof(char *));

    /* 16进制字符串转换成byte */
    hexstr2byte(input, pawd, len);

    /* 解密 */
    AES_cbc_encrypt(input, (unsigned char *)string, len, &key, iv, AES_DECRYPT);
    if (is_print) {
        printf("%s\n", string);
    }
    return string;
}
开发者ID:abgood,项目名称:sqgo,代码行数:30,代码来源:aes_code.c


示例14: aes_enc

/* AES加密 */
void aes_enc(char *string) {
    char *plain = "[email protected]";
    unsigned char iv[AES_BLOCK_SIZE] = {0};
    unsigned char *output;
    int len;
    AES_KEY key;

    /* 设置密钥 */
    if (AES_set_encrypt_key((const unsigned char *)plain, LEN_128, &key) < 0) {
        fprintf(stderr, "Unable to set encryption key in AES\n");
    }

    /* 待加密数据长度 */
    if ((strlen(string) + 1) % AES_BLOCK_SIZE == 0) {
        len = strlen(string) + 1;
    } else {
        len = ((strlen(string) + 1) / AES_BLOCK_SIZE + 1) * AES_BLOCK_SIZE;
    }

    /* 动态分配密文串 */
    output = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *pawd = (char *)calloc(len, sizeof(char *));

    /* 加密 */
    AES_cbc_encrypt((unsigned char *)string, output, len, &key, iv, AES_ENCRYPT);

    /* byte转换16进制字符串 */
    byte2hexstr(pawd, output, len);
    printf("Your Message is Encrypted: %s\n", pawd);

}
开发者ID:abgood,项目名称:sqgo,代码行数:32,代码来源:aes_code.c


示例15: crypt_all

static void crypt_all(int count)
{
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index++)
#endif
	{
		unsigned char master[32];
		unsigned char output[1024];
		unsigned char *iv_in;
		unsigned char iv_out[16];
		int size;
		int page_sz = 1008; /* 1024 - strlen(SQLITE_FILE_HEADER) */
		int reserve_sz = 16; /* for HMAC off case */
		AES_KEY akey;
		pbkdf2((unsigned char *)saved_key[index],  strlen(saved_key[index]), cur_salt->salt, 16, ITERATIONS, (uint32_t *)master);
		memcpy(output, SQLITE_FILE_HEADER, FILE_HEADER_SZ);
		size = page_sz - reserve_sz;
		iv_in = cur_salt->data + size + 16;
		memcpy(iv_out, iv_in, 16);

		if (AES_set_decrypt_key(master, 256, &akey) < 0) {
			fprintf(stderr, "AES_set_derypt_key failed!\n");
		}
		/* decrypting 24 bytes is enough */
		AES_cbc_encrypt(cur_salt->data + 16, output + 16, 24, &akey, iv_out, AES_DECRYPT);
		if (verify_page(output) == 0) {
			cracked[index] = 1;
		}
		else
			cracked[index] = 0;
	}
}
开发者ID:bhargavz,项目名称:pac4mac,代码行数:34,代码来源:strip_fmt_plug.c


示例16: My_AES_CBC_Encrypt

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


示例17: decrypt_chunk

void decrypt_chunk(uint8_t *ctext, uint8_t *ptext, uint32_t chunk_no)
{
  uint8_t iv[CIPHER_BLOCKSIZE];

  compute_iv(chunk_no, iv);
  AES_cbc_encrypt(ctext, ptext, CHUNK_SIZE, &aes_decrypt_key, iv, AES_DECRYPT);
}
开发者ID:Alanaktion,项目名称:vilefault,代码行数:7,代码来源:vfdecrypt.c


示例18: memcpy

int WXBizMsgCrypt::AES_CBCDecrypt( const char * sSource, const uint32_t iSize,
        const char * sKey, uint32_t iKeySize, std::string * poResult )
{
    if ( !sSource || !sKey || iSize < kAesKeySize || iSize % kAesKeySize != 0 || !poResult)
    {
        return -1;
    }
    
    poResult->clear();

    unsigned char * out = (unsigned char*)malloc( iSize );
    if(NULL == out)
    {
        return -1;
    }

    unsigned char key[ kAesKeySize ] = { 0 };
    unsigned char iv[ kAesIVSize ] = {0} ;
    memcpy( key, sKey, iKeySize > kAesKeySize ? kAesKeySize : iKeySize );
    memcpy(iv, key, sizeof(iv) < sizeof(key) ? sizeof(iv) : sizeof(key));

    int iReturnValue = 0;
    AES_KEY aesKey;
    AES_set_decrypt_key( key, 8 * kAesKeySize, &aesKey );
    AES_cbc_encrypt( (unsigned char *)sSource, out, iSize, &aesKey, iv ,AES_DECRYPT);
    if( out[iSize-1] > 0 && out[iSize-1] <= kAesKeySize && (iSize - out[iSize-1]) > 0 )
    {
        poResult->append( (char *)out , iSize - out[iSize-1] );
    } else {
        iReturnValue = -1;
    }

    FREE_PTR(out);
    return iReturnValue;
}
开发者ID:lgyhitler,项目名称:node-weixin-crypto,代码行数:35,代码来源:WXBizMsgCrypt.cpp


示例19: aes_decrypt

static int aes_decrypt(const char* src, int src_len, char** des)
{
	char* tmp = NULL;
	unsigned char key[AES_KEY_SIZE];
	unsigned char iv[AES_IV_SIZE];
	memcpy(iv, AES_IV_NAME, AES_IV_SIZE);
	memcpy(key, AES_KEY_NAME, AES_KEY_SIZE);
	do
	{
		tmp = (char*)malloc(src_len + AES_BLOCK_SIZE + sizeof(LOG_HEADER));
		if (!tmp)
			break;

		LPLOG_HEADER header = (LPLOG_HEADER)tmp;

		header->src_len = src_len;
		header->des_len = ((src_len / AES_BLOCK_SIZE) == 0) ? src_len : src_len + (AES_BLOCK_SIZE - (src_len % AES_BLOCK_SIZE));
		header->len = header->des_len + sizeof(LOG_HEADER);

		AES_KEY aes;
		if( AES_set_encrypt_key((unsigned char*)key, AES_KEY_SIZE * 8, &aes) < 0 )
			break;
		*des = tmp;

		AES_cbc_encrypt((const unsigned char*)src, (unsigned char*)(header->body), src_len, &aes, iv, AES_ENCRYPT);
		return header->len;
	}while(0);
	if (tmp)
		free(tmp);
	return -1;
}
开发者ID:Pinekn,项目名称:Freescale-Drive,代码行数:31,代码来源:net_log.c


示例20: bastrcpy

char *BasketUtils::openssl_crypt(char *data, int datalen, char *key, char *iv, int enc)
{
    char *temp_iv = new char[16];
    bastrcpy(temp_iv, iv, 16);

    AES_KEY aes_key;
    if ( enc == AES_ENCRYPT )
        AES_set_encrypt_key((unsigned char*)key, qstrlen(key)*8, &aes_key);
    else
        AES_set_decrypt_key((unsigned char*)key, qstrlen(key)*8, &aes_key);

    quint8 *out_data = new quint8[datalen];
    if ( !out_data ) {
        errorMsg = trUtf8("Ошибка выделения памяти для выходного буфера!");
        errorState = true;
        return NULL;
    }

    AES_cbc_encrypt((unsigned char*)data, (unsigned char*)out_data, datalen, &aes_key, (unsigned char *)temp_iv, enc);
    if ( !out_data ) {
        errorMsg = trUtf8("Ошибка процесса расшифровки данных!");
        errorState = true;
        return NULL;
    }
    delete [] temp_iv;

    return (char *)out_data;
}
开发者ID:elemc,项目名称:basketpwd,代码行数:28,代码来源:basketutils.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ AES_decrypt函数代码示例发布时间:2022-05-30
下一篇:
C++ AEInstallEventHandler函数代码示例发布时间: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