Class: Blur::Encryption::FiSH

Inherits:
Object
  • Object
show all
Defined in:
library/blur/encryption/fish.rb

Overview

The FiSH algorithm is a combination of Base64 encoding and the blowfish encryption.

Shared text messages are prepended by “+OK”, an older implementation prepends it with “mcps” - Blur drops support for that implementation.

There’s multiple client-implementations available on the official FiSH homepage.

DH1080 Key exchange

The newer FiSH implementation introduces a 1080bit Diffie-Hellman key-exchange mechanism.

Blur does currently not support key exchanges.

Constant Summary collapse

BlockSize =

The standard FiSH block-size.

8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyphrase) ⇒ FiSH

Instantiate a new fish-encryption object.



35
36
37
38
# File 'library/blur/encryption/fish.rb', line 35

def initialize keyphrase
  @keyphrase = keyphrase
  @blowfish = Crypt::Blowfish.new keyphrase
end

Instance Attribute Details

#keyphraseString

Returns the blowfish salt-key.

Returns:

  • (String)

    the blowfish salt-key.



26
27
28
# File 'library/blur/encryption/fish.rb', line 26

def keyphrase
  @keyphrase
end

Instance Method Details

#decrypt(string) ⇒ String

Decrypt an input string using the keyphrase stored in the @blowfish object.

Returns:

  • (String)

    the decrypted string.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'library/blur/encryption/fish.rb', line 57

def decrypt string
  unless string.length % 12 == 0
    raise BadInputError, "input has to be a multiple of 12 characters."
  end
    
  String.new.tap do |buffer|
    string.each_block 12 do |block|
      chunk = @blowfish.decrypt_block Base64.decode block
      buffer.concat chunk
    end
  end.rstrip
end

#encrypt(string) ⇒ String

Encrypt an input string using the keyphrase stored in the @blowfish object.

Returns:

  • (String)

    the encrypted string.



44
45
46
47
48
49
50
51
# File 'library/blur/encryption/fish.rb', line 44

def encrypt string
  String.new.tap do |buffer|
    nullpad(string).each_block do |block|
      chunk = @blowfish.encrypt_block block
      buffer.concat Base64.encode chunk
    end
  end
end