Notekeeper uses Blowfish for encryption. Over the last few days, I separated out the encryption code, cleaned it up, and added some tests. And the result is QBlowfish – a Qt implementation of the Blowfish encryption algorithm.
Blowfish requires the input size (in bytes) to be in multiples of 8. So QBlowfish optionally adds PKCS5 padding to the input data to make its size a multiple of 8. (For example, if the input is only 60 bytes long, 4 bytes will be padded to bring the bytecount to a multiple of 8.) When padding is enabled during decryption, QBlowfish will also remove the padded bytes from the output.
QBlowfish is meant to be compiled with your code – you just drop in 3 files into your project. Then you can do stuff like:
QBlowfish blowfishObj("Some secret key"); blowfishObj.setPaddingEnabled(true); QByteArray clearText("Some stuff to encrypt"); QByteArray encryptedBa = blowfishObj.encrypted(clearText); QByteArray decryptedBa = blowfishObj.decrypted(encryptedBa);
You can get the code from github here.