我正在尝试在 Rails 中创建一个 HMAC 并在 PHP 中验证它。
导轨外壳:
pry(main)>appsecret = '00916893840fe0a29dfdc261efd3a26a&'
pry(main)>OpenSSL::HMAC.hexdigest('sha1', appsecret, 'GET&http%3A%2F%2Fopen.tianya.cn%2Foauth%2Frequest_token.php&oauth_consumer_key%3Dfc69b18eb12bab1e9b35d1093c4de9290516cfdc4%26oauth_nonce%3Dc09e4bf167fbc7eb374b1abb02b5268d%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1366882036%26oauth_version%3D1.0')
=> "8494f6237ee6042a3da8848db21284be17bf6ade"
PHP:
$appsecret = '00916893840fe0a29dfdc261efd3a26a&';
$signature = base64_encode(hash_hmac('sha1', $appsecret, 'GET&http%3A%2F%2Fopen.tianya.cn%2Foauth%2Frequest_token.php&oauth_consumer_key%3Dfc69b18eb12bab1e9b35d1093c4de9290516cfdc4%26oauth_nonce%3Dc09e4bf167fbc7eb374b1abb02b5268d%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1366882036%26oauth_version%3D1.0',true));
var_dump($signature);
导轨结果:8494f6237ee6042a3da8848db21284be17bf6ade
PHP 结果:ayw4/L22fCtXPvPPGaY/Ud8yhMU=
任何帮助将不胜感激!