May 23, 2012

Blowfish for Qt

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");
QByteArray clearText("Some stuff to encrypt");
QByteArray encryptedBa = blowfishObj.encrypted(clearText);
QByteArray decryptedBa = blowfishObj.decrypted(encryptedBa);

You can get the code from github here.

3 Responses to “Blowfish for Qt”

  1. Jonas Kulla says:

    Awesome work!
    I was going to create something similar, but thankfully I get to reuse your debugged and refined code instead :D

  2. roop says:

    @Jonas Thanks. Glad it’s of help. :)
    Which project are you using it for?

  3. Butterfingerss says:

    I am using this in a project of mine…
    I got these errors, could you look at these for me?

    error: undefined reference to QBlowfish::QBlowfish(QByteArray const&)’
    error: undefined reference to QBlowfish::setPaddingEnabled(bool)’
    error: undefined reference to `QBlowfish::encrypted(QByteArray const&)’

    And three more errors but I dont think those are relevant here

Leave a comment

(email will not be published)