go標準庫的學習-crypto/md5

參考:https://studygolang.com/pkgdochtml

導入方式:golang

import "crypto/md5"

md5包實現了MD5哈希算法,參見RFC 1321算法

 

Constants 

const BlockSize = 64

MD5字節塊大小。post

const Size = 16

MD5校驗和字節數。學習

func Sum

func Sum(data []byte) [Size]byte

返回數據data的MD5校驗和。ui

舉例:spa

package main

import (
    "fmt"
    "crypto/md5"
)

func main() {
    data := []byte("The fog is getting thicker!And Leon's getting laaarger!")
    fmt.Printf("%x\n", md5.Sum(data)) //e2c569be17396eca2a2e3c11578123ed
}

 

func New

func New() hash.Hash

返回一個新的使用MD5校驗的hash.Hash接口。code

可見go標準庫的學習-hashhtm

舉例:blog

package main

import (
    "fmt"
    "crypto/md5"
    "io"
)

func main() {
    h := md5.New()
    io.WriteString(h, "The fog is getting thicker!")
    io.WriteString(h, "And Leon's getting laaarger!")
    fmt.Printf("%x\n", h.Sum(nil)) //e2c569be17396eca2a2e3c11578123ed
}
相關文章
相關標籤/搜索