Sha256: 1d79d9a1ccd81604adaf9b184cadb83cdffed4e8264ad76d7e28b8e3eb6ed88e

Contents?: true

Size: 811 Bytes

Versions: 18

Compression:

Stored size: 811 Bytes

Contents

# -*- coding: utf-8 -*-
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

18 entries across 18 versions & 1 rubygems

Version Path
mushikago-sdk-2.4.3 lib//mushikago/auth/signer.rb
mushikago-sdk-2.4.2 lib//mushikago/auth/signer.rb
mushikago-sdk-2.4.1 lib/mushikago/auth/signer.rb
mushikago-sdk-2.4 lib/mushikago/auth/signer.rb
mushikago-sdk-2.2 lib//mushikago/auth/signer.rb
mushikago-sdk-2.1.1 lib/mushikago/auth/signer.rb
mushikago-sdk-2.1.0 lib/mushikago/auth/signer.rb
mushikago-sdk-2.0.0 lib/mushikago/auth/signer.rb
mushikago-sdk-0.4.3 lib/mushikago/auth/signer.rb
mushikago-sdk-0.4.2 lib/mushikago/auth/signer.rb
mushikago-sdk-0.4.1 lib/mushikago/auth/signer.rb
mushikago-sdk-0.4.0 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.7 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.6 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.5 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.4 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.2 lib/mushikago/auth/signer.rb
mushikago-sdk-0.3.1 lib/mushikago/auth/signer.rb