Class: EncryptData::Convert

Inherits:
Crypt
  • Object
show all
Defined in:
lib/encrypt_data.rb

Constant Summary

Constants inherited from Crypt

EncryptData::Crypt::ALGO

Instance Method Summary collapse

Methods inherited from Crypt

crypt, decrypt, encrypt, encryption_key

Constructor Details

#initialize(key = nil) ⇒ Convert

Returns a new instance of Convert.



11
12
13
# File 'lib/encrypt_data.rb', line 11

def initialize(key = nil)
  @key = key unless key.nil?
end

Instance Method Details

#dump(value) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/encrypt_data.rb', line 26

def dump(value)
  begin
    Base64.encode64(
      Crypt.encrypt(
        Marshal.dump(value), @key))
  rescue Exception => e
    puts "\e[31m#{e.message}\e[0m"
  end
end

#load(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/encrypt_data.rb', line 15

def load(value)
  begin
    return if value.nil?
    Marshal.load(
      Crypt.decrypt(
        Base64.decode64(value), @key))
  rescue Exception => e
    puts "\e[31m#{e.message}\e[0m"
  end
end