This is a creation in Article, where the information may have evolved or changed.
It is more convenient to handle it in go.
Func main() {
fmt.Println(md5Str("woGo"))
fmt.Println(sha512Str("woGo"))
fmt.Println(base64DecodeStr(base64EncodeStr("fd")))
}
//md5 verification
Func md5Str(src string) string {
h := md5.New()
h.Write([]byte(src)) // The string to be encrypted is
//fmt.Printf("%s\n", hex.EncodeToString(h.Sum(nil))) // Output the encrypted result
Return hex.EncodeToString(h.Sum(nil))
}
//sha512 verification
Func sha512Str(src string) string {
h := sha512.New()
h.Write([]byte(src)) // The string to be encrypted is
//fmt.Printf("%s\n", hex.EncodeToString(h.Sum(nil))) // Output the encrypted result
Return hex.EncodeToString(h.Sum(nil))
}
//base encoding
Func base64EncodeStr(src string) string {
Return string(base64.StdEncoding.EncodeToString([]byte(src)))
}
//base decoding
Func base64DecodeStr(src string) string {
a, err := (base64.StdEncoding.DecodeString(src))
If err != nil {
Return "error"
}
Return string(a)
}
And in Python, that's just a few lines of code.
Import hashlib, base64
Src =b"woGo"
m= hashlib.md5()
M.update(src)
Print (m.hexdigest())
Print(hashlib.sha512(src).hexdigest())
In fact, whether it is GO language or Python, when decoding, you need to add an exception.
Print(base64.b64encode(b"fd"))
Print(base64.b64decode(base64.b64encode(b"fd"));