Sha256: 9b7160e056aea83c289163ef8978060711270d539c53f2ba4f159d1709f633f8
Contents?: true
Size: 740 Bytes
Versions: 1
Compression:
Stored size: 740 Bytes
Contents
require "base64" require "json" require "jose" module JsonJws::Sign def build_signature(jwk, header, payload) payload = payload.to_json unless payload.is_a?(String) raise "header must be a Hash" unless header.is_a?(Hash) encoded_payload = Base64.urlsafe_encode64(payload) encoded_header = Base64.urlsafe_encode64(header.to_json) JOSE::JWS.sign(jwk, payload, header).to_hash["signature"] end def add_signature(jws, jwk, header, payload) protected_header = Base64.urlsafe_encode64(header.to_json) payload = payload.to_json unless payload.is_a?(String) jws["signatures"] << { "protected" => protected_header, "signature" => build_signature(jwk, header, payload), } jws end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
json_jws-0.1.0 | lib/json_jws/sign.rb |