2016-07-14 11 views
-1

Go를 사용하여 Hmac/SHA1 서명을 생성하려고하지만 Node.js 또는 Python으로 테스트 할 때와 다른 결과가 나타납니다.node.js 또는 Python과 다른 결과로 이동하여 서명 된 Hmac/sha1 메시지

signature := hmac.New(sha1.New, []byte(signKey)) 
signature.Write([]byte(buffer)) 
return hex.EncodeToString(signature.Sum(nil)) 

여기 내 코드는 Node.js를에 있어요 :

return crypto.createHmac('sha1', signKey).update(buffer).digest('hex'); 

파이썬 :

는 여기에 내 코드입니다 당신이 난 것을 알아내는 데 도움이 할 수

return hmac.new(signKey, buffer, sha1).hexdigest() 

잘못하고있는거야?

감사합니다.

답변

1

내 테스트에서 Go와 Node.js에서 동일한 결과가 나타납니다. 즉, 이동 중에 키 및/또는 버퍼 과 달라야합니다.

이동 :

package main 

import (
    "crypto/hmac" 
    "crypto/sha1" 
    "encoding/hex" 
) 

func main() { 
    signKey := "12345" 
    buffer := []byte{1, 2, 3} 
    signature := hmac.New(sha1.New, []byte(signKey)) 
    signature.Write([]byte(buffer)) 
    println(hex.EncodeToString(signature.Sum(nil))) 
} 

Node.js를 :

var crypto = require('crypto'); 

var signKey = "12345"; 
var buffer = "\x01\x02\x03"; 
console.log(
    crypto.createHmac('sha1', signKey).update("\x01\x02\x03", "binary").digest('hex') 
); 
다음

참조 내 테스트 코드입니다