Module: RSwim::Encryption

Defined in:
lib/rswim/encryption.rb

Class Method Summary collapse

Class Method Details

.decrypt(cipher_text, salt) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rswim/encryption.rb', line 13

def decrypt(cipher_text, salt)
  decipher.iv = salt
  message = decipher.update(cipher_text) + decipher.final
  message.force_encoding('UTF-8')
rescue StandardError => e
  raise Error, "Failed to decrypt: #{e.message}"        
end

.encrypt(message) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/rswim/encryption.rb', line 4

def encrypt(message)
  message = message.dup.force_encoding('UTF-8')
  salt = cipher.random_iv        
  cipher_text = cipher.update(message) + cipher.final
  [cipher_text, salt]
rescue StandardError => e
  raise Error, "Failed to encrypt: #{e.message}"
end