Class: Xmlenc::Algorithms::AESGCM
- Inherits:
-
Object
- Object
- Xmlenc::Algorithms::AESGCM
- Defined in:
- lib/xmlenc/algorithms/aes_gcm.rb
Constant Summary collapse
- AUTH_TAG_LEN =
16
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(cipher_value, options = {}) ⇒ Object
- #encrypt(data, options = {}) ⇒ Object
-
#initialize(size) ⇒ AESGCM
constructor
A new instance of AESGCM.
- #key ⇒ Object
- #setup(key = nil) ⇒ Object
Constructor Details
#initialize(size) ⇒ AESGCM
Returns a new instance of AESGCM.
12 13 14 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 12 def initialize(size) @size = size end |
Class Method Details
.[](size) ⇒ Object
7 8 9 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 7 def [](size) new(size) end |
Instance Method Details
#decrypt(cipher_value, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 23 def decrypt(cipher_value, = {}) cipher.decrypt cipher.padding = 0 cipher.key = @key cipher.iv = cipher_value[0...iv_len] cipher.auth_tag = cipher_value[-AUTH_TAG_LEN..-1] cipher.update(cipher_value[iv_len..-(AUTH_TAG_LEN + 1)]) << cipher.final end |
#encrypt(data, options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 32 def encrypt(data, = {}) cipher.encrypt cipher.key = @key cipher.iv = iv cipher.auth_data = '' iv << (cipher.update(data) << cipher.final) << cipher.auth_tag end |
#key ⇒ Object
40 41 42 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 40 def key @key end |
#setup(key = nil) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/xmlenc/algorithms/aes_gcm.rb', line 16 def setup(key = nil) @cipher= nil @iv = nil @key = key || cipher.random_key self end |