Module: Reapal::Encrypt::AES

Defined in:
lib/reapal/encrypt/aes.rb

Class Method Summary collapse

Class Method Details

.decrypt(content, key) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/reapal/encrypt/aes.rb', line 14

def self.decrypt(content, key)
  encrypted = Base64.strict_decode64(content)
  cipher = OpenSSL::Cipher.new("AES-128-ECB")
  cipher.decrypt
  cipher.key = key
  cipher.update(encrypted) + cipher.final
end

.encrypt(content, key) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/reapal/encrypt/aes.rb', line 6

def self.encrypt(content, key)
  cipher = OpenSSL::Cipher.new("AES-128-ECB")
  cipher.encrypt
  cipher.key = key
  encrypted = cipher.update(content) + cipher.final
  Base64.strict_encode64(encrypted)
end