Method: JOSE::JWT#encrypt
- Defined in:
- lib/jose/jwt.rb
#encrypt(jwk, jwe = nil) ⇒ JOSE::EncryptedMap
Encrypts a JOSE::JWT using the jwk and the jwe algorithm.
If "typ" is not specified in the jwe, { "typ" => "JWT" } will be added.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/jose/jwt.rb', line 217 def encrypt(jwk, jwe = nil) plain_text = to_binary if jwe.nil? jwk = JOSE::JWK.from(jwk) jwe = (jwk.is_a?(Array) ? jwk.last : jwk).block_encryptor end if jwe.is_a?(Hash) jwe = JOSE::Map.new(jwe) end if jwe.is_a?(JOSE::Map) and not jwe.has_key?('typ') jwe = jwe.put('typ', 'JWT') end return JOSE::JWK.block_encrypt(jwk, plain_text, jwe) end |