Class: JSON::JWE
- Defined in:
- lib/json/jwe.rb
Defined Under Namespace
Classes: DecryptionFailed, InvalidFormat, UnexpectedAlgorithm
Constant Summary collapse
- NUM_OF_SEGMENTS =
5
Instance Attribute Summary collapse
-
#authentication_tag ⇒ Object
writeonly
Sets the attribute authentication_tag.
-
#cipher_text ⇒ Object
Returns the value of attribute cipher_text.
-
#content_encryption_key ⇒ Object
Returns the value of attribute content_encryption_key.
-
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
-
#input ⇒ Object
Returns the value of attribute input.
-
#iv ⇒ Object
Returns the value of attribute iv.
-
#jwe_encrypted_key ⇒ Object
writeonly
Sets the attribute jwe_encrypted_key.
-
#mac_key ⇒ Object
Returns the value of attribute mac_key.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#plain_text ⇒ Object
Returns the value of attribute plain_text.
-
#private_key_or_secret ⇒ Object
Returns the value of attribute private_key_or_secret.
-
#public_key_or_secret ⇒ Object
Returns the value of attribute public_key_or_secret.
Attributes inherited from JWT
Instance Method Summary collapse
- #content_type ⇒ Object
- #decrypt!(private_key_or_secret) ⇒ Object
- #encrypt!(public_key_or_secret) ⇒ Object
-
#initialize(input) ⇒ JWE
constructor
A new instance of JWE.
- #to_s ⇒ Object
Methods inherited from JWT
#as_json, decode, #encrypt, register_header_keys, #sign, #verify
Constructor Details
#initialize(input) ⇒ JWE
Returns a new instance of JWE.
21 22 23 |
# File 'lib/json/jwe.rb', line 21 def initialize(input) self.input = input.to_s end |
Instance Attribute Details
#authentication_tag=(value) ⇒ Object
Sets the attribute authentication_tag
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def authentication_tag=(value) @authentication_tag = value end |
#cipher_text ⇒ Object
Returns the value of attribute cipher_text.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def cipher_text @cipher_text end |
#content_encryption_key ⇒ Object
Returns the value of attribute content_encryption_key.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def content_encryption_key @content_encryption_key end |
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def encryption_key @encryption_key end |
#input ⇒ Object
Returns the value of attribute input.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def input @input end |
#iv ⇒ Object
Returns the value of attribute iv.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def iv @iv end |
#jwe_encrypted_key=(value) ⇒ Object
Sets the attribute jwe_encrypted_key
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def jwe_encrypted_key=(value) @jwe_encrypted_key = value end |
#mac_key ⇒ Object
Returns the value of attribute mac_key.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def mac_key @mac_key end |
#mode ⇒ Object
Returns the value of attribute mode.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def mode @mode end |
#plain_text ⇒ Object
Returns the value of attribute plain_text.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def plain_text @plain_text end |
#private_key_or_secret ⇒ Object
Returns the value of attribute private_key_or_secret.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def private_key_or_secret @private_key_or_secret end |
#public_key_or_secret ⇒ Object
Returns the value of attribute public_key_or_secret.
12 13 14 |
# File 'lib/json/jwe.rb', line 12 def public_key_or_secret @public_key_or_secret end |
Instance Method Details
#content_type ⇒ Object
25 26 27 |
# File 'lib/json/jwe.rb', line 25 def content_type 'application/jose' end |
#decrypt!(private_key_or_secret) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/json/jwe.rb', line 39 def decrypt!(private_key_or_secret) self.mode = :decryption self.private_key_or_secret = private_key_or_secret decode_segments! cipher.decrypt restore_cipher_keys! self.plain_text = cipher.update(cipher_text) + cipher.final verify_cbc_authentication_tag! if cbc? self end |
#encrypt!(public_key_or_secret) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/json/jwe.rb', line 29 def encrypt!(public_key_or_secret) self.mode = :encryption self.plain_text = input self.public_key_or_secret = public_key_or_secret cipher.encrypt generate_cipher_keys! self.cipher_text = cipher.update(plain_text) + cipher.final self end |
#to_s ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/json/jwe.rb', line 50 def to_s if mode == :encryption [ header.to_json, jwe_encrypted_key, iv, cipher_text, authentication_tag ].collect do |segment| UrlSafeBase64.encode64 segment.to_s end.join('.') else plain_text end end |