Go 语言

Go 语言教程 Go 语言环境安装 Go 语言结构 Go 语言基础语法 Go 语言数据类型 Go 语言变量 Go 语言常量 Go 语言运算符 Go 语言条件语句 Go 语言 if 语句 Go 语言 if...else 语句 Go 语言 if 语句嵌套 Go 语言 switch 语句 Go 语言 select 语句 Go 语言循环语句 Go 语言 for 循环 Go 语言循环嵌套 Go 语言 break 语句 Go 语言 continue 语句 Go 语言 goto 语句 Go 语言函数 Go 语言函数值传递值 Go 语言函数引用传递值 Go 语言函数作为值 Go 语言函数闭包 Go 语言函数方法 Go 语言变量作用域 Go 语言数组 Go 语言多维数组 Go 语言向函数传递数组 Go 语言指针 Go 语言指针数组 Go 语言指向指针的指针 Go 语言指针作为函数参数 Go 语言结构体 Go 语言切片(Slice) Go 语言范围(Range) Go 语言Map(集合) Go 语言递归函数 Go 语言类型转换 Go 语言接口 Go 错误处理 Go 语言开发工具Go 语言标准库

Go 语言标准库


package sha1

import "crypto/sha1"

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

Go语言标准库 >>


  • Constants
  • func Sum(data []byte) [Size]byte
  • func New() hash.Hash
  • Examples

    Go语言标准库 >>


  • New
  • Sum
  • Constants

    const BlockSize = 64

    SHA1的块大小。

    const Size = 20

    SHA1校验和的字节数。

    func Sum

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

    返回数据data的SHA1校验和。

    Example
    data := []byte("This page intentionally left blank.")
    fmt.Printf("% x", sha1.Sum(data))

    Output:

    af 06 49 23 bb f2 30 15 96 aa c4 c2 73 ba 32 17 8e bc 4a 96
    

    func New

    func New() hash.Hash

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

    Example
    h := sha1.New()
    io.WriteString(h, "His money is twice tainted:")
    io.WriteString(h, " 'taint yours and 'taint mine.")
    fmt.Printf("% x", h.Sum(nil))

    Output:

    59 7f 6a 54 00 10 f9 4c 15 d7 18 06 a9 9a 2c 87 10 e7 47 bd