First base64 decode

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-12-12 21:42:37 +01:00
parent ea3558faf6
commit 25734afd39
No known key found for this signature in database
GPG key ID: F941078878347C0C

View file

@ -477,6 +477,8 @@ QByteArray EncryptionHelper::encryptStringSymmetric(const QByteArray& key, const
QByteArray EncryptionHelper::decryptStringAsymmetric(EVP_PKEY *privateKey, const QByteArray& data) { QByteArray EncryptionHelper::decryptStringAsymmetric(EVP_PKEY *privateKey, const QByteArray& data) {
int err = -1; int err = -1;
const QByteArray rawData = QByteArray::fromBase64(data);
auto ctx = EVP_PKEY_CTX_new(privateKey, ENGINE_get_default_RSA()); auto ctx = EVP_PKEY_CTX_new(privateKey, ENGINE_get_default_RSA());
if (!ctx) { if (!ctx) {
qCInfo(lcCse()) << "Could not create the PKEY context."; qCInfo(lcCse()) << "Could not create the PKEY context.";
@ -505,7 +507,7 @@ QByteArray EncryptionHelper::decryptStringAsymmetric(EVP_PKEY *privateKey, const
} }
size_t outlen = 0; size_t outlen = 0;
err = EVP_PKEY_decrypt(ctx, NULL, &outlen, (unsigned char *)data.constData(), data.size()); err = EVP_PKEY_decrypt(ctx, NULL, &outlen, (unsigned char *)rawData.constData(), rawData.size());
if (err <= 0) { if (err <= 0) {
qCInfo(lcCse()) << "Could not determine the buffer length"; qCInfo(lcCse()) << "Could not determine the buffer length";
exit(1); exit(1);
@ -519,7 +521,7 @@ QByteArray EncryptionHelper::decryptStringAsymmetric(EVP_PKEY *privateKey, const
exit(1); exit(1);
} }
if (EVP_PKEY_decrypt(ctx, out, &outlen, (unsigned char *)data.constData(), data.size()) <= 0) { if (EVP_PKEY_decrypt(ctx, out, &outlen, (unsigned char *)rawData.constData(), rawData.size()) <= 0) {
qCInfo(lcCse()) << "Could not decrypt the data."; qCInfo(lcCse()) << "Could not decrypt the data.";
exit(1); exit(1);
} else { } else {