Module: Encrypter

Defined in:
lib/catspeak/encrypter.rb

Class Method Summary collapse

Class Method Details

.cipher(mode, key, text) ⇒ Object



4
5
6
7
8
# File 'lib/catspeak/encrypter.rb', line 4

def self.cipher(mode, key, text)
  cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').send(mode)
  cipher.key = Digest::SHA256.digest(key)
  cipher.update(text) << cipher.final
end

.decrypt(key, text) ⇒ Object



14
15
16
# File 'lib/catspeak/encrypter.rb', line 14

def self.decrypt(key, text)
  cipher(:decrypt, key, text)
end

.encrypt(key, text) ⇒ Object



10
11
12
# File 'lib/catspeak/encrypter.rb', line 10

def self.encrypt(key, text)
  cipher(:encrypt, key, text)
end