Search code examples
encryptionblowfishencryption-symmetric

Blowfish Block Size 64bits - What to do when input is not a multiple of 64bits


I'm creating an application to encrypt a string of unknown length with Blowfish. The input can be of any length, and will therefore not necessarily be a multiple of 8 bytes.

What is the standard method for dealing with this situation? Perhaps fill in the end of the string with 0s? Presumably there's a more elegant way?

Thanks in advance.


Solution

  • There are quite a number of padding mechanisms (wikipedia) that you can choose from. The algorithms vary from simply appending zeros to the end to a padding mechanism that can be validated and/or removed.

    Alternatively, you can use the OFB mode of operation (wikipedia) to convert a block cipher into a stream cipher, and get rid of the requirement for padding.