Class: JSON::JWE
- Defined in:
- lib/json/jwe.rb
Defined Under Namespace
Classes: DecryptionFailed, InvalidFormat, UnexpectedAlgorithm
Instance Attribute Summary collapse
-
#cipher_text ⇒ Object
Returns the value of attribute cipher_text.
-
#encrypted_master_key ⇒ Object
writeonly
Sets the attribute encrypted_master_key.
-
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
-
#input ⇒ Object
Returns the value of attribute input.
-
#integrity_key ⇒ Object
Returns the value of attribute integrity_key.
-
#integrity_value ⇒ Object
writeonly
Sets the attribute integrity_value.
-
#iv ⇒ Object
Returns the value of attribute iv.
-
#master_key ⇒ Object
Returns the value of attribute master_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
- #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
#content_type, decode, #encrypt, register_header_keys, #sign, #verify
Constructor Details
#initialize(input) ⇒ JWE
Returns a new instance of JWE.
19 20 21 |
# File 'lib/json/jwe.rb', line 19 def initialize(input) self.input = input.to_s end |
Instance Attribute Details
#cipher_text ⇒ Object
Returns the value of attribute cipher_text.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def cipher_text @cipher_text end |
#encrypted_master_key=(value) ⇒ Object
Sets the attribute encrypted_master_key
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def encrypted_master_key=(value) @encrypted_master_key = value end |
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def encryption_key @encryption_key end |
#input ⇒ Object
Returns the value of attribute input.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def input @input end |
#integrity_key ⇒ Object
Returns the value of attribute integrity_key.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def integrity_key @integrity_key end |
#integrity_value=(value) ⇒ Object
Sets the attribute integrity_value
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def integrity_value=(value) @integrity_value = value end |
#iv ⇒ Object
Returns the value of attribute iv.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def iv @iv end |
#master_key ⇒ Object
Returns the value of attribute master_key.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def master_key @master_key end |
#mode ⇒ Object
Returns the value of attribute mode.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def mode @mode end |
#plain_text ⇒ Object
Returns the value of attribute plain_text.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def plain_text @plain_text end |
#private_key_or_secret ⇒ Object
Returns the value of attribute private_key_or_secret.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def private_key_or_secret @private_key_or_secret end |
#public_key_or_secret ⇒ Object
Returns the value of attribute public_key_or_secret.
10 11 12 |
# File 'lib/json/jwe.rb', line 10 def public_key_or_secret @public_key_or_secret end |
Instance Method Details
#decrypt!(private_key_or_secret) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/json/jwe.rb', line 33 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_integirity_value! if cbc? self end |
#encrypt!(public_key_or_secret) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/json/jwe.rb', line 23 def encrypt!(public_key_or_secret) self.mode = :encyption 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/json/jwe.rb', line 44 def to_s if mode == :encyption [ header.to_json, encrypted_master_key, iv, cipher_text, integrity_value ].collect do |segment| UrlSafeBase64.encode64 segment.to_s end.join('.') else plain_text end end |