Generating the SHA hash of a string using golang

后端 未结 8 1661
清酒与你
清酒与你 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:58

    h := sha1.New()
    h.Write(content)
    sha := h.Sum(nil)  // "sha" is uint8 type, encoded in base16
    
    shaStr := hex.EncodeToString(sha)  // String representation
    
    fmt.Printf("%x\n", sha)
    fmt.Println(shaStr)
    
    

提交回复
热议问题