Documentation
¶
Overview ¶
パッケージsha256は、FIPS 180-4で定義されたSHA224およびSHA256ハッシュアルゴリズムを実装しています。
Index ¶
Examples ¶
Constants ¶
View Source
const BlockSize = 64
SHA256とSHA224のブロックサイズ(バイト単位)です。
View Source
const Size = 32
SHA256のチェックサムのバイト数。
View Source
const Size224 = 28
SHA224のチェックサムのサイズ(バイト単位)
Variables ¶
This section is empty.
Functions ¶
func New ¶
NewはSHA256ハッシュチェックサムを計算する新しいhash.Hashを返します。Hashは encoding.BinaryMarshalerおよびencoding.BinaryUnmarshalerも実装しており、内部の ハッシュの状態をマーシャリングおよびアンマーシャリングすることができます。
Example ¶
package main import ( "github.com/shogo82148/std/crypto/sha256" "github.com/shogo82148/std/fmt" ) func main() { h := sha256.New() h.Write([]byte("hello world\n")) fmt.Printf("%x", h.Sum(nil)) }
Output: a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447
Example (File) ¶
package main import ( "github.com/shogo82148/std/crypto/sha256" "github.com/shogo82148/std/fmt" "github.com/shogo82148/std/io" "github.com/shogo82148/std/log" "github.com/shogo82148/std/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)) }
Output:
func Sum256 ¶ added in v1.2.0
Sum256はdataのSHA256チェックサムを返します。
Example ¶
package main import ( "github.com/shogo82148/std/crypto/sha256" "github.com/shogo82148/std/fmt" ) func main() { sum := sha256.Sum256([]byte("hello world\n")) fmt.Printf("%x", sum) }
Output: a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.