crypto

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const HashLength = 32

HashLength is the standardized length of a hash.

Variables

This section is empty.

Functions

func Sha3String

func Sha3String(b []byte) string

Sha3String hashes a given message via sha3 and encodes the hashed message to a hex string.

Types

type AesEncrypt

type AesEncrypt struct {
	Key string
}

AesEncrypt

func (*AesEncrypt) Decrypt

func (a *AesEncrypt) Decrypt(src []byte) (strDesc []byte, err error)

Decrypt

Example
aesEnc := AesEncrypt{"1234334"}
arrEncrypt, err := aesEnc.Encrypt([]byte("abcdef"))
if err != nil {
	log.Println(arrEncrypt)
	return
}
aesDec := AesEncrypt{"1234335"}
strMsg, err := aesDec.Decrypt(arrEncrypt)
if err != nil {
	fmt.Printf("error password")
	return
}
fmt.Println(string(strMsg))
Output:

error password

func (*AesEncrypt) Encrypt

func (a *AesEncrypt) Encrypt(strMesg []byte) ([]byte, error)

Encrypt

Example
aesEnc := AesEncrypt{"1234334"}
arrEncrypt, err := aesEnc.Encrypt([]byte("abcdef"))
if err != nil {
	log.Println(arrEncrypt)
	return
}
strMsg, err := aesEnc.Decrypt(arrEncrypt)
if err != nil {
	log.Println(arrEncrypt)
	return
}
fmt.Println(string(strMsg))
Output:

abcdef

type Hash

type Hash [HashLength]byte

Hash represents the streamlined hash type to be used.

func HashFromString

func HashFromString(s string) (Hash, error)

HashFromString returns a Hash type given a hex string.

func NewHash

func NewHash(b []byte) (Hash, error)

NewHash constructs a new hash given a hash, API so it returns an error.

func Sha3

func Sha3(b []byte) Hash

Sha3 hashes a []byte using sha3.

func (Hash) Bytes

func (hash Hash) Bytes() []byte

Bytes converts a given hash to a byte array.

func (Hash) IsNil

func (hash Hash) IsNil() bool

IsNil checks if a given hash is nil.

func (Hash) String

func (hash Hash) String() string

String returns the hash as a hex string.

Jump to

Keyboard shortcuts

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