crypto
# Node.js
const crypto = require("crypto");
const hash = crypto.createHash("sha256").update(Buffer.from("hello")).digest();
console.log(hash.toString("hex"));
1
2
3
4
5
2
3
4
5
Output
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
1
# Go
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
func main() {
hash := sha256.Sum256([]byte("hello"))
fmt.Println(hex.EncodeToString(hash[:]))
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Output
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
1
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22