我正在尝试计算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内容不同。 –