hash

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package hash provides cryptographic hash and hmac functions. It supports multiple hash algorithms including MD2, MD4, MD5, SHA1, SHA2, SHA3, BLAKE2b, BLAKE2s, RIPEMD160, SM3 and so on, with both standard and streaming modes.

Index

Constants

This section is empty.

Variables

View Source
var BufferSize = 64 * 1024

BufferSize buffer size for streaming (64KB is a good balance)

Functions

This section is empty.

Types

type Hasher

type Hasher struct {
	Error error
	// contains filtered or unexported fields
}

Hasher defines a Hasher struct.

func NewHasher

func NewHasher() Hasher

NewHasher returns a new Hasher instance.

func (Hasher) ByBlake2b added in v1.1.2

func (h Hasher) ByBlake2b(size int) Hasher

ByBlake2b computes the BLAKE2b hash or hmac of the input data.

func (Hasher) ByBlake2s added in v1.1.2

func (h Hasher) ByBlake2s(size int) Hasher

ByBlake2s computes the BLAKE2s hash or hmac of the input data.

func (Hasher) ByMd2

func (h Hasher) ByMd2() Hasher

ByMd2 computes the MD2 hash or hmac of the input data.

func (Hasher) ByMd4

func (h Hasher) ByMd4() Hasher

ByMd4 computes the MD4 hash or hmac of the input data.

func (Hasher) ByMd5

func (h Hasher) ByMd5() Hasher

ByMd5 computes the MD5 hash or hmac of the input data.

func (Hasher) ByRipemd160

func (h Hasher) ByRipemd160() Hasher

ByRipemd160 computes the RIPEMD160 hash or hmac of the input data.

func (Hasher) BySha1

func (h Hasher) BySha1() Hasher

BySha1 computes the SHA1 hash or hmac of the input data.

func (Hasher) BySha2

func (h Hasher) BySha2(size int) Hasher

BySha2 computes the SHA2 hash or hmac of the input data.

func (Hasher) BySha3

func (h Hasher) BySha3(size int) Hasher

BySha3 computes the SHA3 hash or hmac of the input data.

func (Hasher) BySm3 added in v1.1.1

func (h Hasher) BySm3() Hasher

BySm3 computes the SM3 hash or hmac of the input data.

func (Hasher) FromBytes

func (h Hasher) FromBytes(b []byte) Hasher

FromBytes encrypts from byte slice.

func (Hasher) FromFile

func (h Hasher) FromFile(f fs.File) Hasher

FromFile encrypts from file.

func (Hasher) FromString

func (h Hasher) FromString(s string) Hasher

FromString encrypts from string.

func (Hasher) ToBase64Bytes

func (h Hasher) ToBase64Bytes() []byte

ToBase64Bytes outputs as base64 byte slice.

func (Hasher) ToBase64String

func (h Hasher) ToBase64String() string

ToBase64String outputs as base64 string.

func (Hasher) ToHexBytes

func (h Hasher) ToHexBytes() []byte

ToHexBytes outputs as hex byte slice.

func (Hasher) ToHexString

func (h Hasher) ToHexString() string

ToHexString outputs as hex string.

func (Hasher) ToRawBytes

func (h Hasher) ToRawBytes() []byte

ToRawBytes outputs as raw byte slice without encoding.

func (Hasher) ToRawString

func (h Hasher) ToRawString() string

ToRawString outputs as raw string without encoding.

func (Hasher) WithKey

func (h Hasher) WithKey(key []byte) Hasher

WithKey sets the key for HMAC calculation from byte slice.

Source Files

  • blake2b.go
  • blake2s.go
  • hasher.go
  • md2.go
  • md4.go
  • md5.go
  • ripemd160.go
  • sha1.go
  • sha2.go
  • sha3.go
  • sm3.go

Directories

Path Synopsis
Package md2 implements the MD2 hash algorithm as defined in RFC 1319.
Package md2 implements the MD2 hash algorithm as defined in RFC 1319.
Package sm3 implements the SM3 hash algorithm as defined in GB/T 32918.1-2016.
Package sm3 implements the SM3 hash algorithm as defined in GB/T 32918.1-2016.

Jump to

Keyboard shortcuts

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