admin管理员组文章数量:1124165
I can not use the output of EVP_DecodeBlock as iv and the ciphertext for decryption use EVP_CIPHER_CTX.
When I initialise the iv or ciphertext by manually writing (with actual values and not 00's):
unsigned char iv[16] = {0x00, 0x00 ...};
unsigned char cipher[16] = {...};
and use them as
EVP_DecryptInit(ctx, EVP_aes_256_cbc(), key, iv));
EVP_DecryptUpdate(ctx, out, &len, cipher, 16); //out is declared as unsigned char out[2048]
I am able to get the required result using evp_decryptfinal. However, when I have the iv and cipher generated using a variable string as:
auto iv_stdstring = ((ciphers[i]["data"][j].toString()).split(".")[1]) //ciphers is a QJsonArray
.split("|")[0]
.toStdString();
auto iv_cstring = iv_stdstring.c_str();
unsigned char iv[16];
EVP_DecodeBlock(
iv, reinterpret_cast<unsigned char *>(const_cast<char *>(iv_cstring)),
strlen(iv_cstring));
The EVP_DecryptFinal call errors out. Weirdly enough, the same code actually works in a different .cpp file when I compile it manually using g++, but doesn't seem to work in qt; The only difference in that .cpp file is that instead of using the auto keyword I just generated the cstring like this:
const char *iv_cstring = "(24 char long iv)";
but even this does not work in the qt code. I also printed the hex characters in the arrays and they match with what's needed. I am very lost on how the same code is working in one instance and not the other.
本文标签: cCan39t use B64 decoded output as IVciphertext in aes256cbc decryptionStack Overflow
版权声明:本文标题:c++ - Can't use B64 decoded output as IVciphertext in aes256cbc decryption - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736615520a1945461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论