Sha256: 3657d00910cbda0811d245b565954c3e77d239606d496f911a5ce51d421596e7

Contents?: true

Size: 787 Bytes

Versions: 7

Compression:

Stored size: 787 Bytes

Contents

require 'base64'
require 'openssl'

module Mushikago
  module Auth
    # 署名を作成するクラス
    class Signer
      # @return [String] シークレットキー
      attr_reader :secret_key

      # @param [String] secret_key シークレットキー
      def initialize secret_key
        @secret_key = secret_key
      end

      # @param [String] string_to_sign 署名の元になる文字列
      # @param [String] digest_method 署名作成のアルゴリズム
      # @return [String] 署名
      def sign(string_to_sign, digest_method='sha256')
        Base64.encode64(
          OpenSSL::HMAC.digest(
            OpenSSL::Digest::Digest.new(digest_method),
            secret_key,
            string_to_sign
          )
        ).strip
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mushikago-sdk-0.2.3 lib/mushikago/auth/signer.rb
mushikago-sdk-0.2.1 lib/mushikago/auth/signer.rb
mushikago-sdk-0.1.8 lib/mushikago/auth/signer.rb
mushikago-sdk-0.1.7 lib/mushikago/auth/signer.rb
mushikago-sdk-0.1.6 lib/mushikago/auth/signer.rb
mushikago-sdk-0.1.5 lib/mushikago/auth/signer.rb
mushikago-sdk-0.1.4 lib/mushikago/auth/signer.rb