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
}

go标准库的学习-crypto sha1介绍到这里,更多go学习请参考编程字典go教程 和问答部分,谢谢大家对编程字典的支持。


原文链接:https://www.cnblogs.com/wanghui-garcia/p/10452457.html