sha256

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 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を返します。 このハッシュは、内部状態をマーシャルおよびアンマーシャルするために 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))
}

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