oswalidos
11th May 2012, 02:17
Hello,
I want to encrypt an mp3 file and then decrypt it back, an RSA sample from the documentation works fine but when it's about encryption of a file content and not a string, problems begin.
Here is the code of encryption :
QFile clearFile("/home/walid/Music/Jennifer.mp3");
if (!clearFile.open(QIODevice::ReadOnly))
qDebug() << "problem while reading " ;
QByteArray clearFileByteArray = clearFile.readAll();
clearFile.close();
qDebug() << "size of clear file " << clearFileByteArray.size() ;
QCA::SecureArray arg = QCA::SecureArray(clearFileByteArray);
qDebug() << arg.size() ;
......
QCA::SecureArray result = pubkey.encrypt(arg, QCA::EME_PKCS1_OAEP);
QByteArray encryptedFileByteArray(result.toByteArray());
qDebug() << " size of encrypted FileByteArray " << result.toByteArray().size() ;
QFile encryptedFile("/home/walid/Music/encrypted.mp3");
if (!encryptedFile.open(QIODevice::WriteOnly))
qDebug() << "problem while opening on write mode";
encryptedFile.write(encryptedFileByteArray);
encryptedFile.close();
the output is :
size of clear file 3788800
size of encrypted File 128
that way i can't decrypt back the file, the method encrypt lost data, i donno why ...
Thanks in advance
I want to encrypt an mp3 file and then decrypt it back, an RSA sample from the documentation works fine but when it's about encryption of a file content and not a string, problems begin.
Here is the code of encryption :
QFile clearFile("/home/walid/Music/Jennifer.mp3");
if (!clearFile.open(QIODevice::ReadOnly))
qDebug() << "problem while reading " ;
QByteArray clearFileByteArray = clearFile.readAll();
clearFile.close();
qDebug() << "size of clear file " << clearFileByteArray.size() ;
QCA::SecureArray arg = QCA::SecureArray(clearFileByteArray);
qDebug() << arg.size() ;
......
QCA::SecureArray result = pubkey.encrypt(arg, QCA::EME_PKCS1_OAEP);
QByteArray encryptedFileByteArray(result.toByteArray());
qDebug() << " size of encrypted FileByteArray " << result.toByteArray().size() ;
QFile encryptedFile("/home/walid/Music/encrypted.mp3");
if (!encryptedFile.open(QIODevice::WriteOnly))
qDebug() << "problem while opening on write mode";
encryptedFile.write(encryptedFileByteArray);
encryptedFile.close();
the output is :
size of clear file 3788800
size of encrypted File 128
that way i can't decrypt back the file, the method encrypt lost data, i donno why ...
Thanks in advance