go标准库的学习-crypto/sha1

参考:https://studygolang.com/pkgdoc

导入方式:

import "crypto/sha1"

sha1包实现了SHA1哈希算法,参见RFC 3174

 

Constants 

const BlockSize = 64

SHA1的块大小。

const Size = 20

SHA1校验和的字节数。

func Sum

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

返回数据data的SHA1校验和。

举例:

package main

import (
    "fmt"
    "crypto/sha1"
)

func main() {
    data := []byte("His money is twice tainted: 'taint yours and 'taint mine.")
    fmt.Printf("%x\n", sha1.Sum(data)) //597f6a540010f94c15d71806a99a2c8710e747bd
}

 

func New

func New() hash.Hash

返回一个新的使用SHA1校验的hash.Hash接口。

可见go标准库的学习-hash

举例:

package main

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

func main() {
    h := sha1.New()
    io.WriteString(h, "His money is twice tainted:")
    io.WriteString(h, " 'taint yours and 'taint mine.")
    fmt.Printf("%x\n", h.Sum(nil)) //597f6a540010f94c15d71806a99a2c8710e747bd
}

 

posted @ 2019-02-28 23:02  慢行厚积  阅读(1538)  评论(0编辑  收藏  举报