本文整理汇总了C++中EVP_DecryptFinal_ex函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_DecryptFinal_ex函数的具体用法?C++ EVP_DecryptFinal_ex怎么用?C++ EVP_DecryptFinal_ex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_DecryptFinal_ex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PEM_do_header
int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
pem_password_cb *callback, void *u)
{
int ok;
int keylen;
long len = *plen;
int ilen = (int) len; /* EVP_DecryptUpdate etc. take int lengths */
EVP_CIPHER_CTX *ctx;
unsigned char key[EVP_MAX_KEY_LENGTH];
char buf[PEM_BUFSIZE];
#if LONG_MAX > INT_MAX
/* Check that we did not truncate the length */
if (len > INT_MAX) {
PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_HEADER_TOO_LONG);
return 0;
}
#endif
if (cipher->cipher == NULL)
return 1;
if (callback == NULL)
keylen = PEM_def_callback(buf, PEM_BUFSIZE, 0, u);
else
keylen = callback(buf, PEM_BUFSIZE, 0, u);
if (keylen <= 0) {
PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_PASSWORD_READ);
return 0;
}
#ifdef CHARSET_EBCDIC
/* Convert the pass phrase from EBCDIC */
ebcdic2ascii(buf, buf, keylen);
#endif
if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]),
(unsigned char *)buf, keylen, 1, key, NULL))
return 0;
ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
return 0;
ok = EVP_DecryptInit_ex(ctx, cipher->cipher, NULL, key, &(cipher->iv[0]));
if (ok)
ok = EVP_DecryptUpdate(ctx, data, &ilen, data, ilen);
if (ok) {
/* Squirrel away the length of data decrypted so far. */
*plen = ilen;
ok = EVP_DecryptFinal_ex(ctx, &(data[ilen]), &ilen);
}
if (ok)
*plen += ilen;
else
PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT);
EVP_CIPHER_CTX_free(ctx);
OPENSSL_cleanse((char *)buf, sizeof(buf));
OPENSSL_cleanse((char *)key, sizeof(key));
return ok;
}
开发者ID:Frrank1,项目名称:node,代码行数:60,代码来源:pem_lib.c
示例2: pt
// ----------------------------------------------------------------------------
bool Crypto::decryptConnectionRequest(BareNetworkString& ns)
{
std::vector<uint8_t> pt(ns.m_buffer.size() - 4, 0);
if (EVP_DecryptInit_ex(m_decrypt, NULL, NULL, NULL, NULL) != 1)
return false;
int dlen;
if (!EVP_CIPHER_CTX_ctrl(m_decrypt, EVP_CTRL_GCM_SET_TAG, 4,
ns.m_buffer.data()))
return false;
if (EVP_DecryptUpdate(m_decrypt, pt.data(), &dlen, ns.m_buffer.data() + 4,
(int)(ns.m_buffer.size() - 4)) != 1)
return false;
if (EVP_DecryptFinal_ex(m_decrypt, unused_16_blocks.data(), &dlen) > 0)
{
assert(dlen == 0);
std::swap(ns.m_buffer, pt);
return true;
}
return false;
} // decryptConnectionRequest
开发者ID:qwertychouskie,项目名称:stk-code,代码行数:26,代码来源:crypto_openssl.cpp
示例3: decrypt
r_int32 AESCipher::decrypt(const unsigned char* raw, const size_t& rawLen, unsigned char* dest, size_t* destLen)
{
if (*destLen < rawLen)
{
return CIPHER_STATUS_BUFFER_ERROR;
}
int ret = 0;
int p_len = rawLen;
int f_len = 0;
if (!EVP_DecryptInit_ex(&m_dctx, NULL, NULL, NULL, NULL))
{
return CIPHER_STATUS_UNKNOWN_ERROR;
}
if (!EVP_DecryptUpdate(&m_dctx, dest, &p_len, raw, rawLen))
{
return CIPHER_STATUS_UNKNOWN_ERROR;
}
if (!EVP_DecryptFinal_ex(&m_dctx, dest+p_len, &f_len))
{
return CIPHER_STATUS_UNKNOWN_ERROR;
}
*destLen = p_len + f_len;
return CIPHER_STATUS_OK;
}
开发者ID:levyhoo,项目名称:netwb,代码行数:31,代码来源:Cipher.cpp
示例4: OldDecrypt
bool OldDecrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext, const unsigned char chKey[32], const unsigned char chIV[16])
{
// plaintext will always be equal to or lesser than length of ciphertext
int nLen = vchCiphertext.size();
int nPLen = nLen, nFLen = 0;
vchPlaintext = CKeyingMaterial(nPLen);
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
if (!ctx) return false;
bool fOk = true;
EVP_CIPHER_CTX_init(ctx);
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen) != 0;
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0]) + nPLen, &nFLen) != 0;
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;
vchPlaintext.resize(nPLen + nFLen);
return true;
}
开发者ID:syscoin,项目名称:syscoin2,代码行数:27,代码来源:crypto_tests.cpp
示例5: CKeyingMaterial
bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext)
{
if (!fKeySet)
return false;
// plaintext will always be equal to or lesser than length of ciphertext
int nLen = vchCiphertext.size();
int nPLen = nLen, nFLen = 0;
vchPlaintext = CKeyingMaterial(nPLen);
EVP_CIPHER_CTX ctx;
bool fOk = true;
EVP_CIPHER_CTX_init(&ctx);
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_cleanup(&ctx);
if (!fOk) return false;
vchPlaintext.resize(nPLen + nFLen);
return true;
}
开发者ID:pcheddar,项目名称:primecoin,代码行数:26,代码来源:crypter.cpp
示例6: DecryptAES256
bool DecryptAES256(const SecureString& sKey, const std::string& sCiphertext, const std::string& sIV, SecureString& sPlaintext)
{
// plaintext will always be equal to or lesser than length of ciphertext
int nLen = sCiphertext.size();
int nPLen = nLen, nFLen = 0;
// Verify key sizes
if(sKey.size() != 32 || sIV.size() != AES_BLOCK_SIZE) {
LogPrintf("crypter DecryptAES256 - Invalid key or block size\n");
return false;
}
sPlaintext.resize(nPLen);
EVP_CIPHER_CTX ctx;
bool fOk = true;
EVP_CIPHER_CTX_init(&ctx);
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*) &sKey[0], (const unsigned char*) &sIV[0]);
if (fOk) fOk = EVP_DecryptUpdate(&ctx, (unsigned char *) &sPlaintext[0], &nPLen, (const unsigned char *) &sCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (unsigned char *) (&sPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_cleanup(&ctx);
if (!fOk) return false;
sPlaintext.resize(nPLen + nFLen);
return true;
}
开发者ID:TheAltcoinBoard,项目名称:XAB-withoutSecp256k1,代码行数:29,代码来源:crypter.cpp
示例7:
size_t AES::CbcDecrypt256(const char *pIn, int iInLen, char *pOut, char *pKey, char *pIv)
{
EVP_CIPHER_CTX *ctx;
if(!(ctx = EVP_CIPHER_CTX_new()))
{
//Error for create
return 0;
}
//Init Encrypt
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, pKey, pIv))
{
return 0;
}
int iLen, iPlainLen;
if(1 != EVP_DecryptUpdate(ctx, pOut, &iLen, pIn, iInLen))
{
return 0;
}
iPlainLen = iLen;
if(1 != EVP_DecryptFinal_ex(ctx, pOut + iPlainLen, &iLen))
{
return 0;
}
iPlainLen += iLen;
EVP_CIPHER_CTX_free(ctx);
return iPlainLen;
}
开发者ID:CongGroup,项目名称:BlindDB,代码行数:34,代码来源:AES.cpp
示例8: unwrap_v2_header
int unwrap_v2_header(char *passphrase, cencrypted_v2_pwheader *header, uint8_t *aes_key, uint8_t *hmacsha1_key)
{
/* derived key is a 3DES-EDE key */
uint8_t derived_key[192/8];
EVP_CIPHER_CTX ctx;
uint8_t *TEMP1;
int outlen, tmplen;
PKCS5_PBKDF2_HMAC_SHA1(passphrase, strlen(passphrase), (unsigned char*)header->kdf_salt, 20,
PBKDF2_ITERATION_COUNT, sizeof(derived_key), derived_key);
print_hex(stderr, derived_key, 192/8);
EVP_CIPHER_CTX_init(&ctx);
/* result of the decryption operation shouldn't be bigger than ciphertext */
TEMP1 = malloc(header->encrypted_keyblob_size);
/* uses PKCS#7 padding for symmetric key operations by default */
EVP_DecryptInit_ex(&ctx, EVP_des_ede3_cbc(), NULL, derived_key, header->blob_enc_iv);
if(!EVP_DecryptUpdate(&ctx, TEMP1, &outlen, header->encrypted_keyblob, header->encrypted_keyblob_size)) {
fprintf(stderr, "internal error (1) during key unwrap operation!\n");
return(-1);
}
if(!EVP_DecryptFinal_ex(&ctx, TEMP1 + outlen, &tmplen)) {
fprintf(stderr, "internal error (2) during key unwrap operation!\n");
return(-1);
}
outlen += tmplen;
EVP_CIPHER_CTX_cleanup(&ctx);
memcpy(aes_key, TEMP1, 16);
memcpy(hmacsha1_key, TEMP1, 20);
return(0);
}
开发者ID:Alanaktion,项目名称:vilefault,代码行数:34,代码来源:vfdecrypt.c
示例9: DecryptString
int DecryptString(char type, char *in, char *out, unsigned char *key, int cipherlen)
{
int plainlen = 0, tmplen;
unsigned char iv[32] =
{ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit_ex(&ctx, CfengineCipher(type), NULL, key, iv);
if (!EVP_DecryptUpdate(&ctx, out, &plainlen, in, cipherlen))
{
CfOut(cf_error, "", "!! Decrypt FAILED");
EVP_CIPHER_CTX_cleanup(&ctx);
return -1;
}
if (!EVP_DecryptFinal_ex(&ctx, out + plainlen, &tmplen))
{
unsigned long err = ERR_get_error();
CfOut(cf_error, "", "decryption FAILED at final of %d: %s\n", cipherlen, ERR_error_string(err, NULL));
EVP_CIPHER_CTX_cleanup(&ctx);
return -1;
}
plainlen += tmplen;
EVP_CIPHER_CTX_cleanup(&ctx);
return plainlen;
}
开发者ID:fbettag,项目名称:core,代码行数:32,代码来源:crypto.c
示例10: CKeyingMaterial
bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext)
{
if (!fKeySet)
return false;
// plaintext will always be equal to or lesser than length of ciphertext
int nLen = vchCiphertext.size();
int nPLen = nLen, nFLen = 0;
vchPlaintext = CKeyingMaterial(nPLen);
bool fOk = true;
EVP_CIPHER_CTX *ctx= EVP_CIPHER_CTX_new();
if(!ctx)
throw std::runtime_error("Error allocating cipher context");
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;
vchPlaintext.resize(nPLen + nFLen);
return true;
}
开发者ID:gridcoin,项目名称:Gridcoin-Research,代码行数:27,代码来源:crypter.cpp
示例11: QByteArray
/**
* Decrypt cipher data
**/
QByteArray OpensslAES::decrypt(const QByteArray &cipherData)
{
if (!m_isValid)
return QByteArray();
/* plaintext will always be equal to or lesser than length of ciphertext*/
int p_len = cipherData.size(), f_len = 0;
unsigned char *plaintext = (unsigned char *)malloc(p_len);
if (!EVP_DecryptInit_ex(&m_decoder, 0, 0, 0, 0)) {
printf("ERROR in EVP_DecryptInit_ex\n");
return QByteArray();
}
if (!EVP_DecryptUpdate(&m_decoder, plaintext, &p_len,
(const unsigned char*)cipherData.constData(), cipherData.size())) {
printf("ERROR in EVP_DecryptUpdate\n");
return QByteArray();
}
if (!EVP_DecryptFinal_ex(&m_decoder, plaintext+p_len, &f_len)) {
printf("ERROR in EVP_DecryptFinal_ex\n");
return QByteArray();
}
return QByteArray((const char*)plaintext, p_len + f_len);
}
开发者ID:dushibaiyu,项目名称:QSocket5Tunnel,代码行数:30,代码来源:opensslaes.cpp
示例12: ERR_load_crypto_strings
bool msl::decrypt_aes256(const void* cipher,const size_t size,const std::string& key,const std::string& iv,std::string& plain)
{
bool success=false;
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
EVP_CIPHER_CTX* ctx=EVP_CIPHER_CTX_new();
uint8_t* temp_data=new uint8_t[(size/16+1)*16];
int temp_length;
int temp_unaligned_length;
if(ctx!=nullptr&&
EVP_DecryptInit_ex(ctx,EVP_aes_256_cbc(),nullptr,(uint8_t*)key.c_str(),(uint8_t*)iv.c_str())!=0&&
EVP_DecryptUpdate(ctx,temp_data,&temp_length,(uint8_t*)cipher,size)!=0&&
EVP_DecryptFinal_ex(ctx,temp_data+temp_length,&temp_unaligned_length)!=0)
{
plain=std::string((char*)temp_data,temp_length+temp_unaligned_length);
success=true;
}
delete[] temp_data;
EVP_CIPHER_CTX_free(ctx);
ERR_free_strings();
EVP_cleanup();
ERR_remove_state(0);
CRYPTO_cleanup_all_ex_data();
return success;
}
开发者ID:mrmoss,项目名称:blasteroids,代码行数:28,代码来源:crypto.cpp
示例13: Java_com_facebook_crypto_cipher_NativeGCMCipher_nativeDecryptFinal
JNIEXPORT int JNICALL Java_com_facebook_crypto_cipher_NativeGCMCipher_nativeDecryptFinal(
JNIEnv* env,
jobject obj,
jbyteArray macTag,
jint tagLength) {
int bytesWritten = 0;
char temp[1];
EVP_CIPHER_CTX* ctx = Get_Cipher_CTX(env, obj);
if (!ctx) {
return CRYPTO_FAILURE;
}
jbyte* tagBytes = (*env)->GetByteArrayElements(env, macTag, NULL);
if (!tagBytes) {
return CRYPTO_FAILURE;
}
int retCode = CRYPTO_SUCCESS;
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, tagLength, tagBytes)) {
retCode = CRYPTO_FAILURE;
}
if (!retCode || !EVP_DecryptFinal_ex(ctx, temp, &bytesWritten)) {
retCode = CRYPTO_FAILURE;
}
(*env)->ReleaseByteArrayElements(env, macTag, tagBytes, JNI_ABORT);
return retCode;
}
开发者ID:Baldwin-Yu,项目名称:conceal,代码行数:32,代码来源:gcm.c
示例14: lib_decryptArray
static bool lib_decryptArray(const EVP_CIPHER *type, const QByteArray &buf, const QByteArray &key, const QByteArray &iv, bool pad, QByteArray *out)
{
QByteArray result(buf.size()+type->block_size);
int len;
EVP_CIPHER_CTX c;
unsigned char *ivp = NULL;
if(!iv.isEmpty())
ivp = (unsigned char *)iv.data();
EVP_CIPHER_CTX_init(&c);
//EVP_CIPHER_CTX_set_padding(&c, pad ? 1: 0);
if(!EVP_DecryptInit_ex(&c, type, NULL, (unsigned char *)key.data(), ivp))
return false;
if(!pad) {
if(!EVP_EncryptUpdate(&c, (unsigned char *)result.data(), &len, (unsigned char *)buf.data(), buf.size()))
return false;
}
else {
if(!EVP_DecryptUpdate(&c, (unsigned char *)result.data(), &len, (unsigned char *)buf.data(), buf.size()))
return false;
}
result.resize(len);
if(pad) {
QByteArray last(type->block_size);
if(!EVP_DecryptFinal_ex(&c, (unsigned char *)last.data(), &len))
return false;
last.resize(len);
ByteStream::appendArray(&result, last);
}
memset(&c, 0, sizeof(EVP_CIPHER_CTX));
*out = result;
return true;
}
开发者ID:psi-im,项目名称:cutestuff,代码行数:34,代码来源:cipher.cpp
示例15: SAF_SymmDecryptFinal
/* 7.3.43 */
int SAF_SymmDecryptFinal(
void *hKeyHandle,
unsigned char *pucOutData,
unsigned int *puiOutDataLen)
{
int ret = SAR_UnknownErr;
SAF_KEY *hkey = (SAF_KEY *)hKeyHandle;
int outlen;
if (!hKeyHandle || !pucOutData || !puiOutDataLen) {
SAFerr(SAF_F_SAF_SYMMDECRYPTFINAL, ERR_R_PASSED_NULL_PARAMETER);
return SAR_IndataErr;
}
if (!hkey->cipher_ctx) {
SAFerr(SAF_F_SAF_SYMMDECRYPTFINAL, SAF_R_DECRYPT_NOT_INITIALIZED);
return SAR_NotInitializeErr;
}
if (!EVP_DecryptFinal_ex(hkey->cipher_ctx, pucOutData, &outlen)) {
SAFerr(SAF_F_SAF_SYMMDECRYPTFINAL, ERR_R_EVP_LIB);
goto end;
}
*puiOutDataLen = (unsigned int)outlen;
ret = SAR_OK;
end:
EVP_CIPHER_CTX_free(hkey->cipher_ctx);
hkey->cipher_ctx = NULL;
return ret;
}
开发者ID:zsdev2015,项目名称:GmSSL,代码行数:33,代码来源:saf_enc.c
示例16: decrypt
uint32_t decrypt(const BYTE *password, const BYTE* data, uint32_t len, BYTE* ans, encrypt_function function) {
EVP_CIPHER_CTX ctx;
uint32_t keyl = 0, ivl = 0;
uint32_t outl = 0, templ = 0;
char *out = calloc(len, sizeof(char));
keyl = EVP_CIPHER_key_length(function());
ivl = EVP_CIPHER_iv_length(function());
BYTE key[keyl];
BYTE iv[ivl];
/* Getting keys and iv */
// Salt is setting in NULL
EVP_BytesToKey(function(), EVP_md5(), NULL, password, strlen(password), 1, key, iv);
/* Initialize context */
EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit_ex(&ctx, function(), NULL, key, iv);
EVP_DecryptUpdate(&ctx, out, &outl, data, len);
EVP_DecryptFinal_ex(&ctx, out + outl, &templ);
outl +=templ;
memcpy(ans, out, outl);
/* Clean context struct */
EVP_CIPHER_CTX_cleanup(&ctx);
free(out);
return outl;
}
开发者ID:eugis,项目名称:crypto-tpe,代码行数:27,代码来源:encryptLib.c
示例17: DecryptString
int DecryptString(char type, const char *in, char *out, unsigned char *key, int cipherlen)
{
int plainlen = 0, tmplen;
unsigned char iv[32] =
{ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
EVP_CIPHER_CTX ctx;
if (key == NULL)
ProgrammingError("DecryptString: session key == NULL");
EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit_ex(&ctx, CfengineCipher(type), NULL, key, iv);
if (!EVP_DecryptUpdate(&ctx, out, &plainlen, in, cipherlen))
{
Log(LOG_LEVEL_ERR, "Failed to decrypt string");
EVP_CIPHER_CTX_cleanup(&ctx);
return -1;
}
if (!EVP_DecryptFinal_ex(&ctx, out + plainlen, &tmplen))
{
unsigned long err = ERR_get_error();
Log(LOG_LEVEL_ERR, "Failed to decrypt at final of cipher length %d. (EVP_DecryptFinal_ex: %s)", cipherlen, ERR_error_string(err, NULL));
EVP_CIPHER_CTX_cleanup(&ctx);
return -1;
}
plainlen += tmplen;
EVP_CIPHER_CTX_cleanup(&ctx);
return plainlen;
}
开发者ID:markburgess,项目名称:Cellibrium,代码行数:35,代码来源:crypto.c
示例18: aesDecrypt
static int aesDecrypt(char* input, int inlen, char* output, int* outlen) {
int c_len;
int f_len;
EVP_CIPHER_CTX ctx;
if (input == NULL || inlen <= 0 || output == NULL || *outlen <= 0) {
return -1;
}
EVP_CIPHER_CTX_init(&ctx);
if (EVP_DecryptInit_ex(&ctx, EVP_aes_128_ecb(), NULL, key, NULL) != 1) {
return -2;
}
if (EVP_DecryptUpdate(&ctx, (unsigned char*)output, &c_len, (const unsigned char*)input,
inlen) != 1) {
return -3;
}
if (EVP_DecryptFinal_ex(&ctx, (unsigned char*)(output + c_len), &f_len) != 1) {
return -4;
}
EVP_CIPHER_CTX_cleanup(&ctx);
*outlen = c_len + f_len;
return 0;
}
开发者ID:cumirror,项目名称:epoll_example,代码行数:29,代码来源:coding.c
示例19: dyn_aes_decrypt
rstatus_t dyn_aes_decrypt(unsigned char *enc_msg, size_t enc_msg_len, struct mbuf *mbuf, unsigned char *aes_key) {
if (ENCRYPTION) {
size_t dec_len = 0;
size_t block_len = 0;
ASSERT(mbuf != NULL && mbuf->last == mbuf->pos);
//if(!EVP_DecryptInit_ex(aes_decrypt_ctx, aes_cipher, NULL, aes_key, aes_iv)) {
if(!EVP_DecryptInit_ex(aes_decrypt_ctx, aes_cipher, NULL, aes_key, aes_key)) {
return DN_ERROR;
}
if(!EVP_DecryptUpdate(aes_decrypt_ctx, mbuf->pos, (int*) &block_len, enc_msg, (int)enc_msg_len)) {
return DN_ERROR;
}
dec_len += block_len;
if(!EVP_DecryptFinal_ex(aes_decrypt_ctx, mbuf->pos + dec_len, (int*) &block_len)) {
return DN_ERROR;
}
dec_len += block_len;
mbuf->last = mbuf->pos + dec_len;
EVP_CIPHER_CTX_cleanup(aes_decrypt_ctx);
return (int) dec_len;
}
mbuf_copy(mbuf, enc_msg, enc_msg_len);
return (int) enc_msg_len;
}
开发者ID:mbrukman,项目名称:netflix-dynomite,代码行数:32,代码来源:dyn_crypto.c
示例20: aes_decrypt
/**
* @brief Decrypt *len bytes of ciphertext.
*
* Code adapted from: http://saju.net.in/code/misc/openssl_aes.c.txt
*
* @param e
* @param plaintext_buf
* @param plaintext_buf_len
* @param ciphertext
* @param ciphertext_len
*
* @return Size of decrypted data on success; -1 on failure
*/
int aes_decrypt(EVP_CIPHER_CTX *e,
unsigned char *plaintext_buf, int plaintext_buf_len,
unsigned char *ciphertext, int ciphertext_len) {
/* because we have padding ON, we must have an extra cipher block size of memory */
int p_len = ciphertext_len, f_len = 0;
if (plaintext_buf_len < p_len + AES_BLOCK_SIZE) {
ERROR("ERROR: plaintext buffer too small");
return -1;
}
if (EVP_DecryptInit_ex(e, NULL, NULL, NULL, NULL) != 1) {
ERROR("ERROR initializing decryption");
return -1;
}
if (EVP_DecryptUpdate(e, plaintext_buf, &p_len, ciphertext, ciphertext_len) != 1) {
ERROR("ERROR decrypting");
return-1;
}
if (EVP_DecryptFinal_ex(e, plaintext_buf+p_len, &f_len) != 1) {
ERROR("ERROR decrypting");
return -1;
}
return p_len + f_len;;
}
开发者ID:BigQNo2,项目名称:xia-core,代码行数:38,代码来源:XSSL_util.c
注:本文中的EVP_DecryptFinal_ex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论