Generating the SHA hash of a string using golang

后端 未结 8 1658
清酒与你
清酒与你 2020-12-23 16:29

Can someone show me a working example of how to generate a SHA hash of a string that I have, say myPassword := \"beautiful\" , using Go 1 ?

The docs pa

8条回答
  •  悲&欢浪女
    2020-12-23 16:42

    Go By Example has a page on sha1 hashing.

    package main
    
    import (
        "fmt"
        "crypto/sha1"
        "encoding/hex"
    )
    
    func main() {
    
        s := "sha1 this string"
        h := sha1.New()
        h.Write([]byte(s))
        sha1_hash := hex.EncodeToString(h.Sum(nil))
    
        fmt.Println(s, sha1_hash)
    }
    

    You can run this example on play.golang.org

提交回复
热议问题