2017-03-21 97 views
-1

我試圖安裝一個應用程序與我的網址登錄,使他們可以驗證,但我似乎無法弄清楚如何複製我是從下頁試圖代碼:https://help.sendowl.com/help/signed-urls#example如何使用Base64編碼執行HMAC-SHA1?

order_id=12345&buyer_name=Test+Man&buyer_email=test%40test.com&product_id=123&signature=QpIEZjEmEMZV%2FHYtinoOj5bqAFw%3D 

[email protected]&buyer_name=Test Man&order_id=12345&product_id=123 

[email protected]&buyer_name=Test Man&order_id=12345&product_id=123&secret=t0ps3cr3t 

publicStr&t0ps3cr3t 

這是步驟:

  1. 一階的參數(刪除簽名)和UNESCAPE 他們:
  2. 下一頁附加您的簽名密鑰:
  3. 生成密鑰簽名用:
  4. 執行HMAC-SHA1摘要與基礎64編碼:QpIEZjEmEMZV/HYtinoOj5bqAFw =

以下是我的嘗試,但最終沒有得到相同的結果:

$signKey = "t0ps3cr3t"; 
$signData = "[email protected]&buyer_name=Test Man&order_id=12345&product_id=123&secret=t0ps3cr3t"; 

$passData = hash_hmac("sha1", $signData, base64_decode(strtr($signKey)), true); 
$passData = base64_encode($passData); 

echo $passData; 

我一直收到x8NXmAmkNBPYCXwtj65mdVJ8lPc=

回答

0

我能夠複製以下內容:花了我一點時間來弄清楚這麼簡單的事情..一直編碼了11個小時。

謝謝。

$data = "[email protected]&buyer_name=Test Man&order_id=12345&product_id=123&secret=t0ps3cr3t"; 
$key = "publicStr&t0ps3cr3t"; 

$pass1 = hash_hmac('sha1', $data, $key, true); 
$pass = base64_encode($pass1); 

echo $pass; 

$pass will return "QpIEZjEmEMZV/HYtinoOj5bqAFw=", the correct value.