Module: K3CloudWebapiSdk::Util::HmacUtil
- Defined in:
- lib/k3cloud_webapi_sdk/util/hmac_util.rb
Class Method Summary collapse
-
.hmac_sha256(content, sign_key, encode_format = 'utf-8') ⇒ Object
Calculate HMAC-SHA256 signature (Ruby equivalent of Python's hmac_util.py).
Class Method Details
.hmac_sha256(content, sign_key, encode_format = 'utf-8') ⇒ Object
Calculate HMAC-SHA256 signature (Ruby equivalent of Python's hmac_util.py)
8 9 10 11 12 |
# File 'lib/k3cloud_webapi_sdk/util/hmac_util.rb', line 8 def self.hmac_sha256(content, sign_key, encode_format = 'utf-8') digest = OpenSSL::HMAC.digest('SHA256', sign_key.encode(encode_format), content.encode(encode_format)) sign_hex = digest.unpack1('H*') Base64.strict_encode64([sign_hex].pack('H*')) end |