Way to encrypt/decrypt files?

Hi there,

What would be an easy approach to save a file as an encrypted file, and decrypt it again? The encryption doesn’t need to be strong, just so the user cannot open it.


The BlowFish class would probably do the trick, I guess.

ok thanks, i’ll look into that.

Sorry to dig this up, but Jules, any chance you could elaborate on how one would go about doing this? I assume I would have to read the file into a MemoryBlock and possibly to a BigInteger or BitArray, and then perform the Blowfish operation?

You have a couple of choices… The easiest would be just encrypt the entire file(maybe MemoryInputStream?), and then if someone wanted to play it they’d need to decode the entire file before playing it back. (Think zipping / unzipping)

I think you mentioned in another thread about audio files…for that you’d want to use an AES or BlowFish(in block mode) cipher across the audio data chunk. (Use these ciphers, as they require alignment when seeking. These ciphers allow you to start decoding mid stream but you need to align(128 or 256 bit boundaries I believe) before decoding).

If you want to encode/decode on the fly, you’d need to write your own AudioFormat reader/writer that did this before being converted to JUCE’s AudioSampleBuffer.

For bonus points you could use RSA to encrypt and validate the key for the cipher! (Otherwise if its the wrong ‘pass’ you are just gonna get white noise!). Your user would need to have a public and private RSA key. You have their public key and a ‘pass’ that they give to decode the file. You use this pass to encrypt the audio(using BlowFish or AES), sign it(encrypt it) with their RSA public key, and store it in the wav file as another chunk. To decode, that user uses their private RSA key to verify(not sure if JUCE’s classes allow verifying, [my experience with RSA is open-ssl]) and get the decryption key from this chunk. If they lose their private RSA key though the file can’t be decoded.