digestV2

package
v1.64.49 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

digestV2 使用方法

  1. Bcrypt

    package main
    
    import (
    	. "fmt"
    
    	"github.com/aid297/aid/digest/digestV2"
    )
    
    func main() {
    	b := digestV2.NewBcrypt("123123")
    	hashed := b.Hash()
    	Printf("hashed: %s\n", hashed)                 // hashed: $2a$10$KnHEwMWRx5MQqx5NSTHJQeP82ehaqXedlZu35UM8.ATqxLAgilCgC
    	Printf("check: %v\n", b.Check(string(hashed))) // check: false
    }
    
  2. MD5

    package main
    
    import (
    	. "fmt"
    
    	"github.com/aid297/aid/digest/digestV2"
    )
    
    func main() {
    	hashed, e := digestV2.NewMD5("123123").Encode()
    	if e != nil {
    		panic(e)
    	}
    	Printf("md5: %v\n", hashed) // md5: 4297f44b13955235245b2497399d7a93
    }
    
  3. SHA

    package main
    
    import (
    	. "fmt"
    
    	"github.com/aid297/aid/digest/digestV2"
    )
    
    func main() {
    	sha := digestV2.NewSHA("123123")
    	hashed, err := sha.Encode256()
    	if err != nil {
    		panic(err)
    	}
    	Printf("hashed: %s\n", hashed) // hashed: 96cae35ce8a9b0244178bf28e4966c2ce1b8385723a96a6b838858cdd6ca0a1e
    
    	sum256 := sha.Encode256Sum256()
    	Printf("sum256: %s\n", sum256) // sum256: 96cae35ce8a9b0244178bf28e4966c2ce1b8385723a96a6b838858cdd6ca0a1e
    }
    
  4. SM3

    package main
    
    import (
    	. "fmt"
    
    	"github.com/aid297/aid/digest/digestV2"
    )
    
    func main() {
    	sm3 := digestV2.NewSM3("123123")
    	hased, err := sm3.Encode()
    	if err != nil {
    		panic(err)
    	}
    	Printf("hased: %s\n", hased) // hased: c68ac63173fcfc537bf22f19a425977029d7dd35ddc5d76b36e58af222dfda39
    }
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bcrypt

type Bcrypt struct {
	// contains filtered or unexported fields
}

func (*Bcrypt) Check

func (my *Bcrypt) Check(hash string) bool

Check 校验

func (*Bcrypt) Hash

func (my *Bcrypt) Hash() (bytes []byte)

Hash 编码

type BcryptEncoder added in v1.64.30

type BcryptEncoder interface {
	Hash() (bytes []byte)
	Check(hash string) bool
}

func NewBcrypt

func NewBcrypt(password string) BcryptEncoder

NewBcrypt 实例化

type MD5

type MD5 struct {
	// contains filtered or unexported fields
}

func (*MD5) Encode

func (my *MD5) Encode() (string, error)

Md5 编码

type MD5HashEncoder added in v1.64.30

type MD5HashEncoder interface{ Encode() (string, error) }

func NewMD5

func NewMD5(original string) MD5HashEncoder

NewMD5 创建MD5编码器

type SHA

type SHA struct {
	// contains filtered or unexported fields
}

func (*SHA) Encode256

func (my *SHA) Encode256() (string, error)

Sha256 摘要算法

func (*SHA) Encode256Sum256

func (my *SHA) Encode256Sum256() string

Sha256Sum256 摘要算法

type SHAEncoder added in v1.64.30

type SHAEncoder interface {
	Encode256() (string, error)
	Encode256Sum256() string
}

func NewSHA

func NewSHA(original string) SHAEncoder

type SM3

type SM3 struct {
	// contains filtered or unexported fields
}

func (*SM3) Encode

func (my *SM3) Encode() (string, error)

Sm3 生成sm3摘要

type SM3Encoder added in v1.64.30

type SM3Encoder interface{ Encode() (string, error) }

func NewSM3

func NewSM3(original string) SM3Encoder

Jump to

Keyboard shortcuts

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