md5

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

md5 パッケージは、RFC 1321で定義されたMD5ハッシュアルゴリズムを実装します。

MD5は暗号学的に破られており、安全なアプリケーションには使用されるべきではありません。

Index

Examples

Constants

View Source
const BlockSize = 64

MD5のブロックサイズ(バイト単位)。

View Source
const Size = 16

MD5チェックサムのバイト数。

Variables

This section is empty.

Functions

func New

func New() hash.Hash

NewはMD5チェックサムを計算する新しい hash.Hash を返します。 このハッシュは、内部状態をマーシャルおよびアンマーシャルするために encoding.BinaryMarshalerencoding.AppendBinary、および encoding.BinaryUnmarshaler も実装しています。

Example
package main

import (
	"github.com/shogo82148/std/crypto/md5"
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/io"
)

func main() {
	h := md5.New()
	io.WriteString(h, "The fog is getting thicker!")
	io.WriteString(h, "And Leon's getting laaarger!")
	fmt.Printf("%x", h.Sum(nil))
}
Output:

e2c569be17396eca2a2e3c11578123ed
Example (File)
package main

import (
	"github.com/shogo82148/std/crypto/md5"
	"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 := md5.New()
	if _, err := io.Copy(h, f); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%x", h.Sum(nil))
}
Output:

func Sum added in v1.2.0

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

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

Example
package main

import (
	"github.com/shogo82148/std/crypto/md5"
	"github.com/shogo82148/std/fmt"
)

func main() {
	data := []byte("These pretzels are making me thirsty.")
	fmt.Printf("%x", md5.Sum(data))
}
Output:

b0804ec967f48520697662a204f5fe72

Types

This section is empty.

Jump to

Keyboard shortcuts

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