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

C++ EVP_DecryptUpdate函数代码示例

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

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



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

示例1: generate_key

/** Decrypt a buffer.
 * @param cipher cipher ID
 * @param enc encrypted buffer
 * @param enc_size number of bytes in @p enc
 * @param plain on return contains plain text data
 * @param plain_size size in bytes of @p plain
 * @return number of bytes that were in the encrypted buffer (this can be shorter if the data
 * did not exactly fit the AES block size.
 */
size_t
BufferDecryptor::decrypt(int cipher, const void *enc, size_t enc_size, void *plain, size_t plain_size)
{
#ifdef HAVE_LIBCRYPTO
  if (keys_.find(cipher) == keys_.end()) {
    generate_key(cipher);
  }

  const EVP_CIPHER *evp_cipher = cipher_by_id(cipher);

  const size_t iv_size = EVP_CIPHER_iv_length(evp_cipher);
  const unsigned char *iv = (const unsigned char *)enc;
  unsigned char *enc_m = (unsigned char *)enc + iv_size;
  enc_size -= iv_size;

  EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  if ( ! EVP_DecryptInit(ctx, evp_cipher, (const unsigned char *)keys_[cipher].c_str(), iv))
  {
    EVP_CIPHER_CTX_free(ctx);
    throw std::runtime_error("Could not initialize cipher context");
  }

  int outl = plain_size;
  if ( ! EVP_DecryptUpdate(ctx,
			   (unsigned char *)plain, &outl, enc_m, enc_size))
  {
    EVP_CIPHER_CTX_free(ctx);
    throw std::runtime_error("DecryptUpdate failed");
  }

  int plen = 0;
  if ( ! EVP_DecryptFinal(ctx, (unsigned char *)plain + outl, &plen) ) {
    EVP_CIPHER_CTX_free(ctx);
    throw std::runtime_error("DecryptFinal failed");
  }
  outl += plen;

  EVP_CIPHER_CTX_free(ctx);
  return outl;
#else
  throw std::runtime_error("Decryption support not available");
#endif
}
开发者ID:timn,项目名称:fawkes,代码行数:52,代码来源:crypto.cpp


示例2: spider_decrypt

int spider_decrypt(void) {
	unsigned char outbuf[LOG_MAX];
	int olen,tlen,n;
	char inbuff[LOG_MAX + EVP_MAX_BLOCK_LENGTH];
	char baz[LOG_MAX + EVP_MAX_BLOCK_LENGTH];
	EVP_CIPHER_CTX ctx;
	int i;

	// hmmm.  how are we going to chop this back into lines and populate
	// the log array?

	if (logfp) {
		fclose(logfp);
	}

	logfp = fopen(LogPath, "rb");

	if (logfp == NULL) {
		fprintf(stderr, "logfp: %s\n", strerror(errno));
		exit(1);
	}

	EVP_CIPHER_CTX_init(&ctx);

	EVP_DecryptInit(&ctx, EVP_bf_cbc(), KEY, IV);

	while ((n = fread(inbuff, 1, LOG_MAX + EVP_MAX_BLOCK_LENGTH, logfp)) > 0) {
		if (EVP_DecryptUpdate(&ctx, outbuf, &olen, inbuff, n) != 1) {
			return 0;
		}
		snprintf(baz, olen+1, "%s", outbuf);
		bzero(&inbuff, LOG_MAX + EVP_MAX_BLOCK_LENGTH);
	}

	if ((i = EVP_DecryptFinal(&ctx, outbuf+olen, &tlen)) != 1) {
		return 0;
	}
	bzero(baz, sizeof(baz));
	snprintf(baz, tlen+1, "%s", outbuf+olen);
	printf("%s", baz);
	EVP_CIPHER_CTX_cleanup(&ctx);
	return 1;
}
开发者ID:nocko,项目名称:Cornell-Spider-for-Unix,代码行数:43,代码来源:spider.c


示例3: EVP_Update_loop

static int EVP_Update_loop(void *args)
{
    loopargs_t *tempargs = *(loopargs_t **)args;
    unsigned char *buf = tempargs->buf;
    EVP_CIPHER_CTX *ctx = tempargs->ctx;
    int outl, count;

    if (decrypt)
        for (count = 0; COND(nb_iter); count++)
            EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
    else
        for (count = 0; COND(nb_iter); count++)
            EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
    if (decrypt)
        EVP_DecryptFinal_ex(ctx, buf, &outl);
    else
        EVP_EncryptFinal_ex(ctx, buf, &outl);
    return count;
}
开发者ID:TomMD,项目名称:ics-openvpn,代码行数:19,代码来源:sslspeed.c


示例4: decrypt_file

int decrypt_file(const char *path, const char *fileName, unsigned char *key) {
	int outlen, inlen;
	
	FILE *file, *temp;
	file = fopen(fileName,"r+b");
	if(file == NULL) {
		return -2;
	}
	char tempName[PATH_SIZE];
	cnct(path,"TemP.TemP",tempName);
	temp = fopen(tempName,"wb");

	unsigned char iv[8] = "DAJ-7l2"; /* вектор инициализации */ 
	unsigned char inbuf[BUF_SIZE], outbuf[BUF_SIZE]; 
	EVP_CIPHER_CTX ctx;
	const EVP_CIPHER * cipher;

	EVP_CIPHER_CTX_init(&ctx);
	cipher = EVP_bf_cbc();

	EVP_DecryptInit(&ctx, cipher, key, iv);

	while(1) {
		inlen = fread(inbuf, 1, BUF_SIZE, file);
		if(inlen <= 0) break;
		if(!EVP_DecryptUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
			return 1;
		fwrite(outbuf, 1, outlen, temp);
	}

	if(!EVP_DecryptFinal(&ctx, outbuf, &outlen)) 
		return 1; 
	fwrite(outbuf, 1, outlen, temp); 
	EVP_CIPHER_CTX_cleanup(&ctx);

	fclose(file);
	fclose(temp);

	remove(fileName);
	rename(tempName,fileName);
	
	return 0;
}
开发者ID:dratdin,项目名称:fuse-file-system,代码行数:43,代码来源:crypt.c


示例5: decrypt

int decrypt(const char *passphrase)
{
    unsigned char key[EVP_MAX_KEY_LENGTH];
    unsigned char iv[EVP_MAX_IV_LENGTH];
    unsigned char salt[8] = {0};
    unsigned char inbuf[256];
    unsigned char outbuf[256 + EVP_MAX_BLOCK_LENGTH];
    int nread, nwrite;
    int outlen;
    EVP_CIPHER_CTX ctx;
    EVP_CIPHER_CTX_init(&ctx);

    genKeyIV(0, passphrase, salt, key, iv);
    EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, key, iv);

    for (;;) {
        if ((nread = read(STDIN_FILENO, inbuf, 255)) < 0) {
            perror("Fail to read");
            return -1;
        } else if (nread == 0)
            break;
        if (!EVP_DecryptUpdate(&ctx, outbuf, &outlen, inbuf, nread)) {
            fprintf(stderr, "Fail to EncryptUpdate!\n");
            EVP_CIPHER_CTX_cleanup(&ctx);
            return -1;
        }
        if ((nwrite = write(STDOUT_FILENO, outbuf, outlen)) < 0) {
            perror("Fail to write");
            return -1;
        }
    }
    if (!EVP_DecryptFinal_ex(&ctx, outbuf, &outlen)) {
        EVP_CIPHER_CTX_cleanup(&ctx);
        return -1;
    }
    if (write(STDOUT_FILENO, outbuf, outlen) < 0) {
        perror("Fail to write");
        return -1;
    }

    EVP_CIPHER_CTX_cleanup(&ctx);
    return 0;
}
开发者ID:binarylu,项目名称:cs631,代码行数:43,代码来源:aed.c


示例6: decrypt_str

int decrypt_str(unsigned char *buffer, const char *data, size_t dataLen, const char *key, size_t *outLen) {
  EVP_CIPHER_CTX *ctx;
  // TODO Bad
  unsigned char iv[16] = {0};
  int outlen1, outlen2;

  if (!(ctx = EVP_CIPHER_CTX_new()))
    return 0;

  if (EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv) != 1)
    return 2;
  if (EVP_DecryptUpdate(ctx, buffer, &outlen1, data, dataLen) != 1)
    return 3;
  if (EVP_DecryptFinal_ex(ctx, buffer + outlen1, &outlen2) != 1)
    return 4;

  *outLen = outlen1 + outlen2;
  return 1;
}
开发者ID:gerner,项目名称:fast_tim_conf,代码行数:19,代码来源:crypt.c


示例7: decrypt

int decrypt(unsigned char *ciphertext,
        int ciphertext_len,
        unsigned char *key,
        unsigned char *iv, unsigned char *plaintext)
{
    EVP_CIPHER_CTX *ctx;

    int len;

    int plaintext_len;

    /* Create and initialise the context */
    if (!(ctx = EVP_CIPHER_CTX_new()))
    handleErrors();

    /* Initialise the decryption operation. IMPORTANT - ensure you use a key
     * and IV size appropriate for your cipher
     * In this example we are using 256 bit AES (i.e. a 256 bit key). The
     * IV size for *most* modes is the same as the block size. For AES this
     * is 128 bits */
    if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
    handleErrors();

    /* Provide the message to be decrypted, and obtain the plaintext output.
     * EVP_DecryptUpdate can be called multiple times if necessary
     */
    if (1 !=EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext,ciphertext_len))
    handleErrors();
    plaintext_len = len;

    /* Finalise the decryption. Further plaintext bytes may be written at
     * this stage.
     */
    if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
    handleErrors();
    plaintext_len += len;

    /* Clean up */
    EVP_CIPHER_CTX_free(ctx);

    return plaintext_len;
}
开发者ID:ktneale,项目名称:aes_demo_code,代码行数:42,代码来源:encrypt.c


示例8: decrypt

int
decrypt (int infd, int outfd)
{
	unsigned char outbuf[IP_SIZE];
	int olen, tlen, n;
	unsigned char inbuff[OP_SIZE];
	EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
	//EVP_CIPHER_CTX_init (ctx);
	EVP_DecryptInit (ctx, EVP_bf_cbc (), key, iv);

	for (;;)
	  {
		  bzero (&inbuff, OP_SIZE);
		  if ((n = read (infd, inbuff, OP_SIZE)) == -1)
		    {
			    perror ("read error");
			    break;
		    }
		  else if (n == 0)
			  break;

		  bzero (&outbuf, IP_SIZE);

		  if (EVP_DecryptUpdate (ctx, outbuf, &olen, inbuff, n) != 1)
		    {
			    printf ("error in decrypt update\n");
			    return 0;
		    }

		  if (EVP_DecryptFinal (ctx, outbuf + olen, &tlen) != 1)
		    {
			    printf ("error in decrypt final\n");
			    return 0;
		    }
		  olen += tlen;
		  if ((n = write (outfd, outbuf, olen)) == -1)
			  perror ("write error");
	  }

	//EVP_CIPHER_CTX_cleanup (ctx);
	return 1;
}
开发者ID:divakarreddy,项目名称:server_side_encryption,代码行数:42,代码来源:code.cpp


示例9: aesDecrypt

size32_t aesDecrypt(MemoryBuffer &out, size32_t inSz, const void *inBytes, size32_t keyLen, const char *key, const char *iv)
{
    if (0 == inSz)
        return 0;
    OwnedEVPCipherCtx ctx(EVP_CIPHER_CTX_new());
    if (!ctx)
        throw makeEVPException(0, "Failed EVP_CIPHER_CTX_new");

    const size32_t cipherBlockSz = 128;
    // from man page - "should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient"
    size32_t outMaxSz = (cipherBlockSz==1) ? inSz : (inSz + cipherBlockSz/8);
    size32_t startSz = out.length();
    byte *outPtr = (byte *)out.reserveTruncate(outMaxSz);

    /* Initialise the decryption operation. IMPORTANT - ensure you use a key
     * and IV size appropriate for your cipher
     * In this example we are using 256 bit AES (i.e. a 256 bit key). The
     * IV size for *most* modes is the same as the block size. For AES this
     * is 128 bits
     * */
    if (!iv) iv = staticAesIV;
    if (1 != EVP_DecryptInit_ex(ctx, getAesCipher(keyLen), nullptr, (const unsigned char *)key, (const unsigned char *)iv))
        throw makeEVPException(0, "Failed EVP_DecryptInit_ex");

    /* Provide the message to be decrypted, and obtain the plaintext output.
     * EVP_DecryptUpdate can be called multiple times if necessary
     */
    int outSz;
    if (1 != EVP_DecryptUpdate(ctx, outPtr, &outSz, (const unsigned char *)inBytes, inSz))
        throw makeEVPException(0, "Failed EVP_DecryptUpdate");
    int plaintext_len = outSz;

    /* Finalise the decryption. Further plaintext bytes may be written at
     * this stage.
     */
    if (1 != EVP_DecryptFinal_ex(ctx, outPtr + outSz, &outSz))
        throw makeEVPException(0, "Failed EVP_DecryptFinal_ex");

    plaintext_len += outSz;
    out.setLength(startSz+plaintext_len); // truncate length of 'out' to final size
    return (size32_t)plaintext_len;
}
开发者ID:AttilaVamos,项目名称:HPCC-Platform,代码行数:42,代码来源:ske.cpp


示例10: malloc

//The partner decryption function to above
unsigned char *blowfish_dec(unsigned char *key, unsigned char* data, int size)
{
	unsigned char* out = malloc(size);
	int outlen;
	int tmplen;
	unsigned char iv[] = {0}; //TODO maybe not this?
	EVP_CIPHER_CTX ctx;
	EVP_CIPHER_CTX_init(&ctx);
	EVP_DecryptInit_ex(&ctx, EVP_bf_ecb(), NULL, key, iv);
	EVP_CIPHER_CTX_set_padding(&ctx, 0);
	
	EVP_DecryptUpdate(&ctx, out, &outlen, data, size);

	if(!EVP_DecryptFinal_ex(&ctx, out + outlen, &tmplen)) {
		ssl_error("Didn't do decrypt final");
	}
	outlen += tmplen;
	EVP_CIPHER_CTX_cleanup(&ctx);
	return out;
}
开发者ID:RaphByrne,项目名称:Cloud-Provider,代码行数:21,代码来源:utilities.c


示例11: aes_decrypt

    array::array* aes_decrypt(array::array* data, array::array* iv, array::array* key) {
        byte* ivec = new byte[iv->length];
        memcpy(ivec, iv->data, iv->length);
        byte* outdata = new byte[data->length * 2];

        int outLen1 = 0, outLen2 = 0;

        EVP_CIPHER_CTX ctx;
        EVP_DecryptInit(&ctx,EVP_aes_256_cbc(),key->data,ivec);
        EVP_DecryptUpdate(&ctx,outdata, &outLen1, data->data, data->length);
        EVP_DecryptFinal(&ctx,outdata + outLen1, &outLen2);

        delete[] ivec;

        array::array* lol = array::create(outLen1 + outLen2, outdata);

        delete[] outdata;

        return lol;
    }
开发者ID:skull0801,项目名称:EP1_OO,代码行数:20,代码来源:crypto.cpp


示例12: CryptUnprotectMemory

BOOL CryptUnprotectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
{
	BYTE* pPlainText;
	int cbOut, cbFinal;
	WINPR_PROTECTED_MEMORY_BLOCK* pMemBlock;

	if (dwFlags != CRYPTPROTECTMEMORY_SAME_PROCESS)
		return FALSE;

	if (!g_ProtectedMemoryBlocks)
		return FALSE;

	pMemBlock = (WINPR_PROTECTED_MEMORY_BLOCK*) ListDictionary_GetItemValue(g_ProtectedMemoryBlocks, pData);

	if (!pMemBlock)
		return FALSE;

	/* AES Decryption */

	cbOut = pMemBlock->cbData + AES_BLOCK_SIZE - 1;
	pPlainText = (BYTE*) malloc(cbOut);

	EVP_DecryptInit_ex(&(pMemBlock->dec), NULL, NULL, NULL, NULL);
	EVP_DecryptUpdate(&(pMemBlock->dec), pPlainText, &cbOut, pMemBlock->pData, pMemBlock->cbData);
	EVP_DecryptFinal_ex(&(pMemBlock->dec), pPlainText + cbOut, &cbFinal);

	CopyMemory(pMemBlock->pData, pPlainText, pMemBlock->cbData);
	SecureZeroMemory(pPlainText, pMemBlock->cbData);
	free(pPlainText);

	ListDictionary_Remove(g_ProtectedMemoryBlocks, pData);

	/* AES Cleanup */

	EVP_CIPHER_CTX_cleanup(&(pMemBlock->enc));
	EVP_CIPHER_CTX_cleanup(&(pMemBlock->dec));

	free(pMemBlock);

	return TRUE;
}
开发者ID:10084462,项目名称:FreeRDP,代码行数:41,代码来源:crypto.c


示例13: decipher_evp

static char *	decipher_evp (const unsigned char *key, int keylen, const unsigned char *ciphertext, int cipherlen, const EVP_CIPHER *type, int *outlen, int ivsize)
{
        unsigned char *outbuf;
	unsigned char	*iv = NULL;
	unsigned long errcode;
	int	outlen2;
        EVP_CIPHER_CTX a;
        EVP_CIPHER_CTX_init(&a);
	EVP_CIPHER_CTX_set_padding(&a, 0);

	if (ivsize > 0)
		iv = new_malloc(ivsize);
	outbuf = new_malloc(cipherlen + 1024);
	if (ivsize > 0)
		memcpy(iv, ciphertext, ivsize);

        EVP_DecryptInit_ex(&a, type, NULL, NULL, iv);
	EVP_CIPHER_CTX_set_key_length(&a, keylen);
	EVP_CIPHER_CTX_set_padding(&a, 0);
        EVP_DecryptInit_ex(&a, NULL, NULL, key, NULL);

        if (EVP_DecryptUpdate(&a, outbuf, outlen, ciphertext, cipherlen) != 1)
		yell("EVP_DecryptUpdate died.");
	if (EVP_DecryptFinal_ex(&a, outbuf + (*outlen), &outlen2) != 1)
		yell("EVP_DecryptFinal_Ex died.");
	*outlen += outlen2;

        EVP_CIPHER_CTX_cleanup(&a);

	ERR_load_crypto_strings();
	while ((errcode = ERR_get_error()))
	{
	    char r[256];
	    ERR_error_string_n(errcode, r, 256);
	    yell("ERROR: %s", r);
	}

	if (ivsize > 0)
		new_free(&iv);
	return outbuf;
}
开发者ID:Cloudxtreme,项目名称:epic5,代码行数:41,代码来源:crypto.c


示例14: decrypt_sym

int decrypt_sym(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext) {
	EVP_CIPHER_CTX *ctx;

	int len;

	int plaintext_len;

	if(!(ctx = EVP_CIPHER_CTX_new())) handleErrors();

	if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) handleErrors();

	if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) handleErrors();
	plaintext_len = len;

	if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) handleErrors();
	plaintext_len += len;

	EVP_CIPHER_CTX_free(ctx);

	return plaintext_len;
}
开发者ID:danielemidi,项目名称:SecureAuditLog,代码行数:21,代码来源:crypto_sym.c


示例15: codec_aes_decrypt

/**
 * AES-ECB-PKCS5Padding解密
 *
 * LUA示例:
 * local codec = require('codec')
 * local src = [[...]] --BASE64密文
 * local key = [[...]] --16位数字串
 * local bs = codec.base64_decode(src)
 * local dst = codec.aes_decrypt(bs, key)
 */
static int codec_aes_decrypt(lua_State *L)
{
    size_t len;
    const char *src = luaL_checklstring(L, 1, &len);
    char *key = luaL_checkstring(L, 2);

    EVP_CIPHER_CTX ctx;
    EVP_CIPHER_CTX_init(&ctx);

    int ret = EVP_DecryptInit_ex(&ctx, EVP_aes_128_ecb(), NULL, (unsigned char *)key, NULL);
    if(ret != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        return luaL_error(L, "EVP decrypt init error");
    }

    int n, wn;
    char dst[len];
    memset(dst, 0, len);

    ret = EVP_DecryptUpdate(&ctx, (unsigned char *)dst, &wn, (unsigned char *)src, len);
    if(ret != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        return luaL_error(L, "EVP decrypt update error");
    }
    n = wn;

    ret = EVP_DecryptFinal_ex(&ctx, (unsigned char *)(dst + n), &wn);
    if(ret != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        return luaL_error(L, "EVP decrypt final error");
    }
    EVP_CIPHER_CTX_cleanup(&ctx);
    n += wn;

    lua_pushlstring(L, dst, n);
    return 1;
}
开发者ID:mashijie,项目名称:lua-codec,代码行数:50,代码来源:codec.c


示例16: symmetric_decrypt

int symmetric_decrypt(char* ciphertext, char* plaintext,char* key,int enctextsize)
{

 	int nc; /* amount of bytes [de]crypted at each step */
  	int nctot; /* total amount of encrypted bytes */
  	int pt_len; /* plain text size */
  	int ct_len; /* encrypted text size */
  	int ct_ptr; /* first available entry in the buffer */
  	int msg_len; /* message length */
	int k_size;

 	/* Context allocation */
  	EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));

  	/* Context initialization */
  	EVP_CIPHER_CTX_init(ctx);

 	/* Context setup for encryption */
  	EVP_DecryptInit(ctx, EVP_des_ecb(), NULL, NULL);

	/* Decryption key setup */
  	EVP_DecryptInit(ctx, NULL, key, NULL);

 	/* Encryption */
  	nc = 0;
  	nctot = 0;
  	ct_ptr = 0;
   
	EVP_DecryptUpdate(ctx, &plaintext[ct_ptr], &nc, ciphertext, enctextsize);
    
  	ct_ptr += nc;
  	nctot += nc;
  	
	EVP_DecryptFinal(ctx, &plaintext[ct_ptr], &nc);

  	nctot += nc;
	
	return nctot;

}
开发者ID:habt,项目名称:openssl-encryption,代码行数:40,代码来源:server.c


示例17: aes_decrypt

int aes_decrypt(EVP_CIPHER_CTX *d, int in,int out)
{
	int inlen=0,flen=0,outlen=0;
	char inbuf[SIZE+AES_BLOCK_SIZE];				/****** CHECK ???? ****/
	char outbuf[SIZE+AES_BLOCK_SIZE];

	if(!EVP_DecryptInit_ex(d, NULL, NULL, NULL, NULL)) 
	{
		perror("\n Eror in DECinit:");
		return 1;
	}    
	
	while((inlen = read(in,inbuf,SIZE)) >0)
	{
		if(!EVP_DecryptUpdate(d,(unsigned char*)outbuf, &outlen,(unsigned char*)inbuf,inlen)) 
		{
			perror("\n Error,DECRYPT_UPDATE:");
			return 1;
		}
		if((write(out,outbuf,outlen)) != outlen)
		{
			perror("\n ERROR,Writing dec bytes:");
			return 1;
		}	
	
	}
        
	if(!EVP_DecryptFinal_ex(d,(unsigned char*)outbuf,&flen)) 
	{
		perror("\n Error,DECRYPT_FINAL:");
		return 1;
	}
	if((write(out,outbuf,flen)) != flen)
	{
		perror("\n ERROR,Writng FINAL dec bytes:");
		return 1;
	}
        return 0;
}
开发者ID:stevezhougs,项目名称:mpro,代码行数:39,代码来源:aes2.c


示例18: handle_crypt_error

int Crypt::dec_data(uint8_t *cipher_text, int cipher_text_len, uint8_t *plain_text, uint64_t k_nas_enc) {
	EVP_CIPHER_CTX *ctx;
	int len;
	int plain_text_len;

	if (!(ctx = EVP_CIPHER_CTX_new())) {
		handle_crypt_error();
	}
	if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) {
		handle_crypt_error();
	}
	if (1 != EVP_DecryptUpdate(ctx, plain_text, &len, cipher_text, cipher_text_len)) {
		handle_crypt_error();
	}
	plain_text_len = len;
	if (1 != EVP_DecryptFinal_ex(ctx, plain_text + len, &len)) { 
		handle_crypt_error(); 
	}
	plain_text_len += len;
	EVP_CIPHER_CTX_free(ctx);
	return plain_text_len;
}
开发者ID:pratiksatapathy,项目名称:vEPC-handover-implementation,代码行数:22,代码来源:security.cpp


示例19: DecryptBuf

bool RarVolume::DecryptBuf(const uint8 in[16], uint8 out[16])
{
#ifdef HAVE_OPENSSL
	uint8 outbuf[32];
	int outlen = 0;
	if (!EVP_DecryptUpdate((EVP_CIPHER_CTX*)m_context, outbuf, &outlen, in, 16)) return false;
	memcpy(out, outbuf + outlen, 16);
	debug("decrypted: %s", *Util::FormatBuffer((const char*)out, 16));
	return true;
#elif defined(HAVE_NETTLE)
	aes_decrypt((aes_ctx*)m_context, 16, out, in);
	for (int i = 0; i < 16; i++)
	{
		out[i] ^= m_decryptIV[i];
	}
	memcpy(m_decryptIV, in, 16);
	debug("decrypted: %s", *Util::FormatBuffer((const char*)out, 16));
	return true;
#else
	return false;
#endif
}
开发者ID:sanderjo,项目名称:nzbget,代码行数:22,代码来源:RarReader.cpp


示例20: TripleDESDecrypt

/**
* 功能描述:3DES解密
* @param pData:原始数据
* @param ilen: 原始数据长度
* @param ppDecryptData: 解密后数据
* @return -1: 失败, 其他: 解密数据长度
**/
int TripleDESDecrypt(const char* pData, int ilen, char** ppDecryptData)
{
    /*密钥*/
    unsigned char key[24] = {43,14,54,109,109,8,84,87,116,30,19,68,35,51,83,72,16,2,83,48,117,85,9,80};
    /*初始化向量*/
    unsigned char iv[8] = {111,121,47,42,75,34,33,124};

    EVP_CIPHER_CTX ctx;
    EVP_CIPHER_CTX_init(&ctx);
    int rc = EVP_EncryptInit_ex(&ctx,EVP_des_ede3_cbc(),NULL,key,iv);
    if (rc != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        return -1;
    }

    int outlen = ilen + 1;
    *ppDecryptData = (char*)malloc(outlen);
    memset(*ppDecryptData, 0 , outlen);

    rc = EVP_DecryptUpdate(&ctx, (unsigned char*)(*ppDecryptData), &outlen, (unsigned char*)pData, ilen);
    if(rc != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        free(*ppDecryptData);
        return -1;
    }
    int outlentmp = 0;
    rc = EVP_DecryptFinal_ex(&ctx, (unsigned char*)(*ppDecryptData) + outlen,&outlentmp);
    if(rc != 1)
    {
        EVP_CIPHER_CTX_cleanup(&ctx);
        free(*ppDecryptData);
        return -1;
    }
    outlen += outlentmp;
    EVP_CIPHER_CTX_cleanup(&ctx);
    return outlen;
}
开发者ID:baby0119,项目名称:sslapply,代码行数:46,代码来源:encryption.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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