Sha256: fe92258bfcc57b075d3a27ea48c6166b826c792f7782993109f249f8407b870d
Contents?: true
Size: 864 Bytes
Versions: 18
Compression:
Stored size: 864 Bytes
Contents
# frozen_string_literal: true module LedgerSync module Util class Signer HMAC_SHA1_DIGEST = OpenSSL::Digest.new('sha1') HMAC_SHA256_DIGEST = OpenSSL::Digest.new('sha256') attr_reader :str def initialize(str:) @str = str end def hmac_sha1(key:, escape: false) ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA1_DIGEST, key, str)).strip ret = self.class.escape(str: ret) if escape ret end def hmac_sha256(key:, escape: false) ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA256_DIGEST, key, str)).strip ret = self.class.escape(str: ret) if escape ret end def self.escape(str:) CGI.escape(str).gsub(/\+/, '%20') end def self.unescape(str:) CGI.unescape(str.gsub(/%20/, '+')) end end end end
Version data entries
18 entries across 18 versions & 1 rubygems