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 :
Qt Code:
  1. QFile clearFile("/home/walid/Music/Jennifer.mp3");
  2. if (!clearFile.open(QIODevice::ReadOnly))
  3. qDebug() << "problem while reading " ;
  4. QByteArray clearFileByteArray = clearFile.readAll();
  5. clearFile.close();
  6. qDebug() << "size of clear file " << clearFileByteArray.size() ;
  7. QCA::SecureArray arg = QCA::SecureArray(clearFileByteArray);
  8. qDebug() << arg.size() ;
  9. ......
  10. QCA::SecureArray result = pubkey.encrypt(arg, QCA::EME_PKCS1_OAEP);
  11. QByteArray encryptedFileByteArray(result.toByteArray());
  12. qDebug() << " size of encrypted FileByteArray " << result.toByteArray().size() ;
  13. QFile encryptedFile("/home/walid/Music/encrypted.mp3");
  14. if (!encryptedFile.open(QIODevice::WriteOnly))
  15. qDebug() << "problem while opening on write mode";
  16. encryptedFile.write(encryptedFileByteArray);
  17. encryptedFile.close();
To copy to clipboard, switch view to plain text mode 

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