module JSON::JWK::JWKizable::EC
def coordinates
def coordinates unless @coordinates hex = public_key.to_bn.to_s(16) data_len = hex.length - 2 hex_x = hex[2, data_len / 2] hex_y = hex[2 + data_len / 2, data_len / 2] @coordinates = { x: hex_x, y: hex_y } @coordinates[:d] = private_key.to_s(16) if private_key? end @coordinates end
def curve_name
def curve_name case group.curve_name when 'prime256v1' :'P-256' when 'secp384r1' :'P-384' when 'secp521r1' :'P-521' when 'secp256k1' :secp256k1 else raise UnknownAlgorithm.new('Unknown EC Curve') end end
def to_jwk(ex_params = {})
def to_jwk(ex_params = {}) params = { kty: :EC, crv: curve_name, x: Base64.urlsafe_encode64([coordinates[:x]].pack('H*'), padding: false), y: Base64.urlsafe_encode64([coordinates[:y]].pack('H*'), padding: false) }.merge ex_params params[:d] = Base64.urlsafe_encode64([coordinates[:d]].pack('H*'), padding: false) if private_key? JWK.new params end