Class: FunWith::Passwords::Crypt

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_with/passwords/crypt.rb

Constant Summary collapse

IV =
"b2f7zaf14kagpd3j76ulddjxytvhjnzvna7diacozrui7afx4d7kj0cxj4ch1of1z7in376vah4kwkarwls0vbtosraovy7d4ci"

Class Method Summary collapse

Class Method Details

.decrypt(encrypted_message, key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/fun_with/passwords/crypt.rb', line 6

def self.decrypt( encrypted_message, key )
  cipher = OpenSSL::Cipher::AES256.new( :CBC )
  cipher.decrypt
  cipher.key = self.stretch_key(key)
  cipher.iv  = IV
  
  msg = cipher.update( encrypted_message )
  msg << cipher.final
  msg
end

.encrypt(plaintext, key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/fun_with/passwords/crypt.rb', line 17

def self.encrypt( plaintext, key )
  cipher = OpenSSL::Cipher::AES256.new( :CBC )
  cipher.encrypt
  cipher.key = self.stretch_key(key)
  cipher.iv  = IV
  
  encrypted_message = cipher.update( plaintext )
  encrypted_message << cipher.final
  encrypted_message
end