Class: JOSE::JWE::ENC_AES_GCM
- Inherits:
-
Struct
- Object
- Struct
- JOSE::JWE::ENC_AES_GCM
- Defined in:
- lib/jose/jwe/enc_aes_gcm.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
Returns the value of attribute bits.
-
#cek_len ⇒ Object
Returns the value of attribute cek_len.
-
#cipher_name ⇒ Object
Returns the value of attribute cipher_name.
-
#iv_len ⇒ Object
Returns the value of attribute iv_len.
Class Method Summary collapse
-
.from_map(fields) ⇒ Object
JOSE::JWE callbacks.
Instance Method Summary collapse
-
#algorithm ⇒ Object
JOSE::JWE::ENC callbacks.
- #block_decrypt(aad_cipher_text_cipher_tag, cek, iv) ⇒ Object
- #block_encrypt(aad_plain_text, cek, iv) ⇒ Object
- #next_cek ⇒ Object
- #next_iv ⇒ Object
- #to_map(fields) ⇒ Object
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits
1 2 3 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 1 def bits @bits end |
#cek_len ⇒ Object
Returns the value of attribute cek_len
1 2 3 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 1 def cek_len @cek_len end |
#cipher_name ⇒ Object
Returns the value of attribute cipher_name
1 2 3 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 1 def cipher_name @cipher_name end |
#iv_len ⇒ Object
Returns the value of attribute iv_len
1 2 3 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 1 def iv_len @iv_len end |
Class Method Details
.from_map(fields) ⇒ Object
JOSE::JWE callbacks
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 5 def self.from_map(fields) case fields['enc'] when 'A128GCM' return new('aes-128-gcm', 128, 16, 12), fields.delete('enc') when 'A192GCM' return new('aes-192-gcm', 192, 24, 12), fields.delete('enc') when 'A256GCM' return new('aes-256-gcm', 256, 32, 12), fields.delete('enc') else raise ArgumentError, "invalid 'enc' for JWE: #{fields['enc'].inspect}" end end |
Instance Method Details
#algorithm ⇒ Object
JOSE::JWE::ENC callbacks
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 24 def algorithm case cipher_name when 'aes-128-gcm' return 'A128GCM' when 'aes-192-gcm' return 'A192GCM' when 'aes-256-gcm' return 'A256GCM' else raise ArgumentError, "unhandled JOSE::JWE::ENC_AES_GCM cipher name: #{cipher_name.inspect}" end end |
#block_decrypt(aad_cipher_text_cipher_tag, cek, iv) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 37 def block_decrypt(aad_cipher_text_cipher_tag, cek, iv) aad, cipher_text, cipher_tag = aad_cipher_text_cipher_tag cipher = OpenSSL::Cipher.new(cipher_name) cipher.decrypt cipher.key = cek cipher.iv = iv cipher.padding = 0 cipher.auth_data = aad cipher.auth_tag = cipher_tag plain_text = cipher.update(cipher_text) + cipher.final return plain_text end |
#block_encrypt(aad_plain_text, cek, iv) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 50 def block_encrypt(aad_plain_text, cek, iv) aad, plain_text = aad_plain_text cipher = OpenSSL::Cipher.new(cipher_name) cipher.encrypt cipher.key = cek cipher.iv = iv cipher.padding = 0 cipher.auth_data = aad cipher_text = cipher.update(plain_text) + cipher.final return cipher_text, cipher.auth_tag end |
#next_cek ⇒ Object
62 63 64 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 62 def next_cek return SecureRandom.random_bytes(cek_len) end |
#next_iv ⇒ Object
66 67 68 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 66 def next_iv return SecureRandom.random_bytes(iv_len) end |
#to_map(fields) ⇒ Object
18 19 20 |
# File 'lib/jose/jwe/enc_aes_gcm.rb', line 18 def to_map(fields) return fields.put('enc', algorithm) end |