?
This document uses PHP Chinese website manual Release
import "crypto/sha256"
概述
索引
示例
軟件包sha256 實現(xiàn) FIPS 180-4 中定義的 SHA224 和 SHA256 哈希算法。
常量
func New() hash.Hash
func New224() hash.Hash
func Sum224(data []byte) (sum224 [Size224]byte)
func Sum256(data []byte) [Size]byte
New New (File) Sum256
sha256.go sha256block.go sha256block_amd64.go sha256block_decl.go
SHA256 和SHA224 的塊大小以字節(jié)為單位。
const BlockSize = 64
SHA256 校驗和的大?。ㄒ宰止?jié)為單位)。
const Size = 32
SHA224 校驗和的大?。ㄒ宰止?jié)為單位)。
const Size224 = 28
func New() hash.Hash
New 返回一個新的 hash.Hash 計算 SHA256 校驗和。
package mainimport ("crypto/sha256""fmt")func main() { h := sha256.New() h.Write([]byte("hello world\n")) fmt.Printf("%x", h.Sum(nil))}
package mainimport ("crypto/sha256""fmt""io""log""os")func main() { f, err := os.Open("file.txt")if err != nil { log.Fatal(err)} defer f.Close() h := sha256.New()if _, err := io.Copy(h, f); err != nil { log.Fatal(err)} fmt.Printf("%x", h.Sum(nil))}
func New224() hash.Hash
New224 返回一個新的 hash.Hash 計算 SHA224 校驗和。
func Sum224(data []byte) (sum224 [Size224]byte)
Sum224 返回數(shù)據(jù)的 SHA224 校驗和。
func Sum256(data []byte) [Size]byte
Sum256 返回數(shù)據(jù)的 SHA256 校驗和。
package mainimport ("crypto/sha256""fmt")func main() { sum := sha256.Sum256([]byte("hello world\n")) fmt.Printf("%x", sum)}