crypto

package
v0.0.0-...-8b4ee15 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	RSA_KEY_SIZE = 1024
)

Variables

This section is empty.

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密,密码必须小于72位

func EcdsaDecrypt

func EcdsaDecrypt(privateKey *ecdsa.PrivateKey, ciphertext []byte) ([]byte, error)

使用私钥解密消息

func EcdsaEncrypt

func EcdsaEncrypt(publicKey *ecdsa.PublicKey, message []byte) ([]byte, error)

使用公钥加密消息

func EcdsaGenerateKey

func EcdsaGenerateKey() (string, string, error)

func EcdsaGenerateSignature

func EcdsaGenerateSignature(privateKeyStr, hashStr string) (string, error)

func EcdsaVerifySignature

func EcdsaVerifySignature(publicKeyStr, hashStr, signatureStr string) (bool, error)

func GenerateRandomAESKey

func GenerateRandomAESKey(keySize int) ([]byte, error)

GenerateRandomAESKey 生成随机AES密钥 keySize: 16(128-bit), 24(192-bit) 或 32(256-bit)

func GenerateRsaKeys

func GenerateRsaKeys() (string, string)

func Md5v

func Md5v(str string, salt string) string

Md5v md5 后置盐值(password + salt)

func Md5vMulti

func Md5vMulti(str string, salt string, iteration int) string

Md5vMulti iteration:加密次数

func Sha256v

func Sha256v(str string, salt string) string

Md5v md5 加盐加密

Types

type AES

type AES interface {
	AESEncrypt(plaintext []byte, key []byte, iv ...byte) (ciphertext []byte, err error)
	AESDecrypt(ciphertext []byte, key []byte, iv ...byte) (plaintext []byte, err error)
	AESEncryptHexString(plaintextHex string, keyHex string, ivHex string) (ciphertextHex string, err error)
	AESDecryptHexString(ciphertextHex string, keyHex string, ivHex string) (plaintextHex string, err error)
}

func NewCBC

func NewCBC() AES

func NewCFB

func NewCFB() AES

func NewGCM

func NewGCM() AES

type CBC

type CBC struct{}

CBC 实现 AES 接口

func (*CBC) AESDecrypt

func (c *CBC) AESDecrypt(ciphertext []byte, key []byte, iv ...byte) (plaintext []byte, err error)

AESDecrypt AES-CBC 解密(二进制版)

func (*CBC) AESDecryptHexString

func (c *CBC) AESDecryptHexString(ciphertextHex string, keyHex string, ivHex string) (plaintextHex string, err error)

AESDecryptString AES-CBC 解密(字符串版)

func (*CBC) AESEncrypt

func (c *CBC) AESEncrypt(plaintext []byte, key []byte, iv ...byte) (ciphertext []byte, err error)

AESEncrypt AES-CBC 加密(二进制版)

func (*CBC) AESEncryptHexString

func (c *CBC) AESEncryptHexString(plaintextHex string, keyHex string, ivHex string) (ciphertextHex string, err error)

AESEncryptString AES-CBC 加密(字符串版)

type CFB

type CFB struct{}

CFB 实现 AES 接口

func (*CFB) AESDecrypt

func (c *CFB) AESDecrypt(ciphertext []byte, key []byte, iv ...byte) (plaintext []byte, err error)

AESDecrypt AES-CFB 解密(二进制版)

func (*CFB) AESDecryptHexString

func (c *CFB) AESDecryptHexString(ciphertextHex string, keyHex string, ivHex string) (plaintextHex string, err error)

AESDecryptString AES-CFB 解密(字符串版)

func (*CFB) AESEncrypt

func (c *CFB) AESEncrypt(plaintext []byte, key []byte, iv ...byte) (ciphertext []byte, err error)

AESEncrypt AES-CFB 加密(二进制版)

func (*CFB) AESEncryptHexString

func (c *CFB) AESEncryptHexString(plaintextHex string, keyHex string, ivHex string) (ciphertextHex string, err error)

AESEncryptString AES-CFB 加密(字符串版)

type GCM

type GCM struct{}

GCM 实现 AES 接口

func (*GCM) AESDecrypt

func (g *GCM) AESDecrypt(ciphertext []byte, key []byte, iv ...byte) (plaintext []byte, err error)

AESDecrypt AES-GCM 解密(二进制版)

func (*GCM) AESDecryptHexString

func (g *GCM) AESDecryptHexString(ciphertextHex string, keyHex string, ivHex string) (plaintextHex string, err error)

AESDecryptString AES-GCM 解密(字符串版)

func (*GCM) AESEncrypt

func (g *GCM) AESEncrypt(plaintext []byte, key []byte, iv ...byte) (ciphertext []byte, err error)

AESEncrypt AES-GCM 加密(二进制版)

func (*GCM) AESEncryptHexString

func (g *GCM) AESEncryptHexString(plaintextHex string, keyHex string, ivHex string) (ciphertextHex string, err error)

AESEncryptString AES-GCM 加密(字符串版)

Jump to

Keyboard shortcuts

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