【发布时间】:2015-02-21 21:51:43
【问题描述】:
我正在尝试计算 sha1,但 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 内容不同。