/**
func Sum256(data []byte) [Size]byte
Sum256 returns the SHA256 checksum of the data.
func EncodeToString(src []byte) string
EncodeToString returns the hexadecimal encoding of src.
*/
package main
import (
"crypto/sha256"
"encoding/hex"
"log"
)
func calculateHash(toBeHashed string) string {
hashInBytes := sha256.Sum256([]byte(toBeHashed))
hashStr := hex.EncodeToString(hashInBytes[:])
log.Printf("%s\n %s\n", toBeHashed, hashStr)
return hashStr
}
func main() {
calculateHash("test1")
}
来源:https://www.cnblogs.com/udont/p/12508421.html