Module: PWS::Encryptor

Defined in:
lib/pws/encryptor.rb

Overview

This encryptor class wraps around openssl to simplify en/decryption using AES 256 CBC Please note: Failed en/decryptions will raise errors

Constant Summary collapse

CIPHER =
'aes-256-cbc'

Class Method Summary collapse

Class Method Details

.decrypt(encrypted_data, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/pws/encryptor.rb', line 10

def decrypt(encrypted_data, options = {})
  crypt(
    :decrypt,
    encrypted_data,
    options[:key],
    options[:iv],
  )
end

.encrypt(unecrypted_data, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/pws/encryptor.rb', line 19

def encrypt(unecrypted_data, options = {})
  crypt(
    :encrypt,
    unecrypted_data,
    options[:key],
    options[:iv],
  )
end

.random_ivObject



28
29
30
# File 'lib/pws/encryptor.rb', line 28

def random_iv
  OpenSSL::Cipher.new(CIPHER).random_iv
end