class Xmlenc::Algorithms::AESGCM
Constants
- AUTH_TAG_LEN
Public Class Methods
[](size)
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 7 def [](size) new(size) end
new(size)
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 12 def initialize(size) @size = size end
Public Instance Methods
decrypt(cipher_value, options = {})
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 23 def decrypt(cipher_value, options = {}) 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 = {})
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 32 def encrypt(data, options = {}) cipher.encrypt cipher.key = @key cipher.iv = iv cipher.auth_data = '' iv << (cipher.update(data) << cipher.final) << cipher.auth_tag end
key()
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 40 def key @key end
setup(key = nil)
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 16 def setup(key = nil) @cipher= nil @iv = nil @key = key || cipher.random_key self end
Private Instance Methods
cipher()
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 54 def cipher @cipher ||= OpenSSL::Cipher.new("aes-#{@size}-gcm") end
iv()
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 46 def iv @iv ||= cipher.random_iv end
iv_len()
click to toggle source
# File lib/xmlenc/algorithms/aes_gcm.rb, line 50 def iv_len cipher.iv_len end