cryptoutil

package
v2.0.0-alpha.19 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSignExpired   = errors.New("sign expired")
	ErrSignInvalid   = errors.New("sign invalid")
	ErrExpireInvalid = errors.New("expire invalid")
	ErrExpireMissing = errors.New("expire missing")
)

Functions

func AesCBCDecrypt

func AesCBCDecrypt(cryted, key string) result.Result[string]

func AesCBCEncrypt

func AesCBCEncrypt(orig, key string) result.Result[string]

func CheckPassword

func CheckPassword(hash, password string) error

CheckPassword checks to see if the password matches the hashed password.

func Decrypt

func Decrypt(ciphertext []byte, key *[32]byte) (plaintext []byte, err error)

Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.

func Encrypt

func Encrypt(plaintext []byte, key *[32]byte) (ciphertext []byte, err error)

Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.

func HashPassword

func HashPassword(password string) result.Result[string]

func Hmac

func Hmac(key, data string) string

Hmac key随意设置 data 要加密数据

func HmacSha256

func HmacSha256(key, data string) string

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, size int) []byte

PKCS7Padding 补码

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding 去码

func SecureKey

func SecureKey() *[32]byte

SecureKey generates a random 256-bit key for Encrypt() and Decrypt(). It panics if the source of randomness fails.

func SecureToken

func SecureToken(lengths ...int) string

SecureToken create a new random token

Types

type HMACSign

type HMACSign struct {
	SecretKey []byte
}

func (HMACSign) Sign

func (s HMACSign) Sign(data string, expire int64) string

func (HMACSign) Verify

func (s HMACSign) Verify(data, sign string) error

Jump to

Keyboard shortcuts

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