-2
有人可以幫我把下面的Fantom代碼轉換成Javascript嗎?從Fantom轉換到Javascript
// compute salted hmac
hmac := Buf().print("${username}:${userSalt}").hmac("SHA-1", password.toBuf).toBase64
// now compute login digest using nonce
digest := "${hmac}:${nonce}".toBuf.toDigest("SHA-1").toBase64
我已經能夠計算使用CryptoJS的hmac
變量:
var hash = CryptoJS.HmacSHA1("alice:6s6Q5Rn0xZP0LPf89bNdv+65EmMUrTsey2fIhim/wKU=", "secret");
var hmac = hash.toString(CryptoJS.enc.Base64);
但我仍然摘要掙扎。
如果您發佈一個例子,這裏是我使用的測試變量:
username : "alice"
password : "secret"
userSalt : "6s6Q5Rn0xZP0LPf89bNdv+65EmMUrTsey2fIhim/wKU="
nonce : "3da210bdb1163d0d41d3c516314cbd6e"
hmac : "z9NILqJ3QHSG5+GlDnXsV9txjgo="
digest : "B2B3mIzE/+dqcqOJJ/ejSGXRKvE="
,你能否告訴我們到目前爲止你已經嘗試了什麼? – leDominatre
我嘗試使用2個網站:http://tools.bin63.com/hmac-generator和https://caligatio.github.io/jsSHA/事實是我不完全理解我需要傳遞哪些變量,以及何時?如果我只知道如何傳遞變量和什麼時候hmac ...? –