GolangNote

Golang笔记

GoLang 对字符串作md5加密

Permalink

GoLang 对字符串作md5加密

GoLang 对字符串作md5加密

Go: md5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main

import (
    "crypto/md5"
    "encoding/hex"
    "fmt"
)

func main() {
    data := []byte("hello world")
    s := fmt.Sprintf("%x", md5.Sum(data))
    fmt.Println(s)

    // 也可以用这种方式
    h := md5.New()
    h.Write(data)
    s = hex.EncodeToString(h.Sum(nil))
    fmt.Println(s)
}

输出:

plaintext: md5
1
2
5eb63bbbe01eeed093cb22bb8f5acdc3
5eb63bbbe01eeed093cb22bb8f5acdc3

Related articles

Write a Comment to "GoLang 对字符串作md5加密"

Submit Comment Login
Based on Golang + fastHTTP + youdb | go1.16 Processed in 1ms