class TencentCloud::Common::Sign

def sign_v1(method, endpoint, path, data, secret_key, sign_method)

def sign_v1(method, endpoint, path, data, secret_key, sign_method)
  sign = method + endpoint + path + '?'
  params = []
  data.sort.each do |item|
    params << "#{item[0]}=#{item[1]}"
  end
  sign += params.join('&')
  case sign_method
  when 'HmacSHA256'
    digest = OpenSSL::Digest.new('sha256')
  when 'HmacSHA1'
    digest = OpenSSL::Digest.new('sha1')
  else
    raise TencentCloudSDKException.new('signMethod invalid', 'signMethod only support (HmacSHA1, HmacSHA256)')
  end
  Base64.encode64(OpenSSL::HMAC.digest(digest, secret_key, sign))
end