Module: Flutterwave::Utils::EncryptionManager

Defined in:
lib/flutterwave/utils/encryption_manager.rb

Constant Summary collapse

KEY =
Flutterwave::Utils::Constants::KEY

Class Method Summary collapse

Class Method Details

.decrypt(text, key = KEY) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/flutterwave/utils/encryption_manager.rb', line 20

def self.decrypt(text, key = KEY)
  key = digest(key)
  cipher = OpenSSL::Cipher::Cipher.new('des-ede3')
  cipher.decrypt
  cipher.key = key
  plain_text = cipher.update(Base64.decode64(text.to_s))

  plain_text << cipher.final
end

.digest(key) ⇒ Object



30
31
32
33
34
# File 'lib/flutterwave/utils/encryption_manager.rb', line 30

def self.digest(key)
  digest = Digest::MD5.digest(key)

  digest + digest[0, 8]
end

.encrypt(text, key = KEY) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/flutterwave/utils/encryption_manager.rb', line 9

def self.encrypt(text, key = KEY)
  key = digest(key)
  cipher = OpenSSL::Cipher::Cipher.new('des-ede3')
  cipher.encrypt
  cipher.key = key
  cipher_text = cipher.update(text.to_s)
  cipher_text << cipher.final

  Base64.encode64(cipher_text).gsub(/\n/, '')
end