# Io Reference

Encryption / Blowfish / Blowfish

The Blowfish object can be used to do encryption and decryption using the Blowfish keyed, symmetric block cipher.

Example encryption and decription;

    key := "secret"
    data := "this is a message"

    encryptedData := Blowfish clone setKey(key) encrypt(data)
    decryptedData := Blowfish clone setKey(key) decrypt(encryptedData)

Or using the stream API:

    key := "secret"
    data := "this is a message"

    cipher = Blowfish clone
    cipher setIsEncrypting(true)
    cipher setKey(key)
    cipher beginProcessing
    cipher inputBuffer appendSeq(data)
    cipher process
    cipher endProcess
    encryptedData := cipher outputBuffer

    cipher = Blowfish clone
    cipher setIsEncrypting(false)
    cipher setKey(key)
    cipher beginProcessing
    cipher inputBuffer appendSeq(encryptedData)
    cipher process
    cipher endProcess
    decryptedData := cipher outputBuffer

beginProcessing

Sets the key from the key slot and initializes the cipher.
decrypt(aSequence)

Returns an decrypted version of aSequence.
encrypt(aSequence)

Returns an encrypted version of aSequence.
endProcessing

Finish processing remaining bytes of inputBuffer.
inputBuffer

Returns the input buffer.
outputBuffer

Returns the output buffer.
process

Process the inputBuffer and appends the result to the outputBuffer. The processed inputBuffer is emptied except for the spare bytes at the end which don't fit into a cipher block.
setIsEncrypting(aBool)

If aBool is true, encrypting mode is on, otherwise, decrypting mode is on.