Class: Grassy::AES
- Inherits:
-
Object
- Object
- Grassy::AES
- Defined in:
- lib/grassy/aes.rb
Instance Method Summary collapse
- #decrypt(payload) ⇒ Object
- #encrypt(payload) ⇒ Object
-
#initialize(key, iv) ⇒ AES
constructor
A new instance of AES.
Constructor Details
#initialize(key, iv) ⇒ AES
Returns a new instance of AES.
3 4 5 6 |
# File 'lib/grassy/aes.rb', line 3 def initialize(key, iv) @key = key @iv = iv end |
Instance Method Details
#decrypt(payload) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/grassy/aes.rb', line 16 def decrypt(payload) cipher = OpenSSL::Cipher::AES128.new(:CBC) cipher.decrypt cipher.key = @key cipher.iv = @iv cipher.update(Base64.decode64(payload)) + cipher.final end |
#encrypt(payload) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/grassy/aes.rb', line 8 def encrypt(payload) cipher = OpenSSL::Cipher::AES128.new(:CBC) cipher.encrypt cipher.key = @key cipher.iv = @iv Base64.strict_encode64(cipher.update(payload) + cipher.final) end |