Ruby way to generate a HMAC-SHA1 signature for OAuth

后端 未结 2 1962
轻奢々
轻奢々 2020-12-23 14:15

I\'m writing a small ruby program to play with Twitter over OAuth and have yet to find a right way to do the HMAC-SHA1 signature. So far, I messed around with

2条回答
  •  甜味超标
    2020-12-23 15:05

    def hmac_sha1(data, secret=HOST_KEY)
        require 'base64'
        require 'cgi'
        require 'openssl'
        hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), secret.encode("ASCII"), data.encode("ASCII"))
        return hmac
    end
    

提交回复
热议问题