sha256

package
v1.21.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 1 Imported by: 0

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

func New() hash.Hash

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 New224

func New224() hash.Hash

New224はSHA224チェックサムを計算する新しいhash.Hashを返します。

func Sum224 added in v1.2.0

func Sum224(data []byte) [Size224]byte

Sum224はデータのSHA224ハッシュ値を返します。

func Sum256 added in v1.2.0

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL