我正在嘗試計算sha1,但是sha1與openssl命令不匹配。crypto/sha1不匹配openssl命令
我計算了一個空文件哈希像這樣我的MacBook:
$ touch test.txt
$ openssl sha1 -hex test.txt
SHA1(test.txt)= da39a3ee5e6b4b0d3255bfef95601890afd80709
而且here是一個簡單的測試代碼,我有:
package main
import "fmt"
import "crypto/sha1"
func main() {
hash := sha1.New()
hash.Write([]byte{0x00})
fmt.Printf("Hash got %x, expected da39a3ee5e6b4b0d3255bfef95601890afd80709", hash.Sum(nil))
}
這裏是輸出看到輸出不匹配,任何人知道我在做什麼錯了?
Hash got 5ba93c9db0cff93f52b521d7420e43f6eda2784f, expected da39a3ee5e6b4b0d3255bfef95601890afd80709
在哪一點你喂'test.txt'內容到sha1?你不計算0字節的sha1嗎? –
對不起 - 你說test.txt是空的。但空單元可能與單字節0內容不同。 –