Module: Aescryptor

Defined in:
lib/aescryptor.rb,
lib/aescryptor/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.decrypt(encrypted_data, key, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object



8
9
10
11
12
13
14
# File 'lib/aescryptor.rb', line 8

def decrypt(encrypted_data, key, iv=nil, cipher_type="AES-256-CBC")
  aes = OpenSSL::Cipher::Cipher.new(cipher_type)
  aes.decrypt
  aes.key = key
  aes.iv = iv if iv != nil
  aes.update([encrypted_data].pack("H*")) + aes.final
end

.encrypt(data, key, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object



16
17
18
19
20
21
22
# File 'lib/aescryptor.rb', line 16

def encrypt(data, key,  iv=nil, cipher_type="AES-256-CBC")
  aes = OpenSSL::Cipher::Cipher.new(cipher_type)
  aes.encrypt
  aes.key = key
  aes.iv = iv if iv != nil
  (aes.update(data) + aes.final).unpack("H*")[0]
end