golang sha256

/**
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")
}

猜你喜欢

转载自www.cnblogs.com/udont/p/12508421.html