1 回答

TA貢獻1921條經驗 獲得超9個贊
該echo命令還發送一個換行符,因此您的第一個示例計算字符串的 SHA-512 校驗和"hello sha world\n"。
如果你在 Go 中使用相同的,你會得到相同的輸出:
s := sha512.New()
s.Write([]byte("hello sha world\n"))
fmt.Println(hex.EncodeToString(s.Sum(nil)))
或者簡單地說:
fmt.Printf("%x\n", sha512.Sum512([]byte("hello sha world\n")))
這些輸出(在Go Playground上試試):
9c5b761a9bf8f74da84c57101669b8042b860ca5871a15c4e729758ad1dee58d562ddf8fa303ada1f3e0278fdff4af9a72f57ce0514be98f6a959daabda926f5
如果要計算 bash 中某些文本的 SHA-512 檢出而不使用尾隨換行符,請使用如下-n參數echo:
echo -n "hello sha world" | openssl dgst -sha512 -hex
這輸出與原始 Go 代碼相同:
d13fa494d2609a6f67e906de96d92788bd8ab46dec0f5e48d8cdb8c540628a752aa135262aa5804dcc907e261abe4472faf01fc13eb97e4e8c85e5c0438f2acb
- 1 回答
- 0 關注
- 227 瀏覽
添加回答
舉報