Class: Blur::Encryption::FiSH
- Inherits:
-
Object
- Object
- Blur::Encryption::FiSH
- 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
-
#keyphrase ⇒ String
The blowfish salt-key.
Instance Method Summary collapse
-
#decrypt(string) ⇒ String
Decrypt an input string using the keyphrase stored in the @blowfish object.
-
#encrypt(string) ⇒ String
Encrypt an input string using the keyphrase stored in the @blowfish object.
-
#initialize(keyphrase) ⇒ FiSH
constructor
Instantiate a new fish-encryption object.
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
#keyphrase ⇒ String
Returns 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.
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.
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 |