crypto

package
v0.0.0-...-13b8838 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

@Author Eric @Date 2024/6/9 23:30:00 @Desc 加解密相关的处理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aes256Decrypt

func Aes256Decrypt(key []byte, cipherBytes []byte) ([]byte, error)

Aes256Decrypt

@Description: AES256解密,CBC模式,PKCS7Padding,iv就是密钥
@param key 加密key
@param ciphertext 密文
@return []byte 解密后数据
@return error

func Aes256DecryptBase64

func Aes256DecryptBase64(key []byte, ciphertext string) ([]byte, error)

Aes256DecryptBase64

@Description: AES256解密,CBC模式,PKCS7Padding,iv就是密钥
@param key 加密key
@param ciphertext base64的密文
@return []byte 解密后数据
@return error

func Aes256Encrypt

func Aes256Encrypt(key []byte, plaintext []byte) ([]byte, error)

Aes256Encrypt

@Description: AES256加密,CBC模式,PKCS7Padding,iv就是密钥
@param key 加密key
@param plaintext 原始数据
@return byte 返回加密后数据
@return error

func Aes256EncryptBase64

func Aes256EncryptBase64(key []byte, plaintext string) (string, error)

Aes256EncryptBase64

@Description: AES256加密,CBC模式,PKCS7Padding,iv就是密钥
@param key 加密key
@param plaintext 原始数据
@return string 返回base64之后数据
@return error

func AesGCMDecrypt

func AesGCMDecrypt(key []byte, ciphertext []byte) ([]byte, error)

AesGCMDecrypt

@Description: AES-GCM 解密
@param key 加密key
@param ciphertext 密文(包括nonce和ciphertext)
@return []byte 返回解密后的数据
@return error

func AesGCMEncrypt

func AesGCMEncrypt(key []byte, plaintext []byte) ([]byte, error)

AesGCMEncrypt

@Description: AES-GCM 加密
@param key 加密key
@param plaintext 原始数据
@return []byte 返回加密后的数据(包括nonce和ciphertext)
@return error

func GenerateCRC32

func GenerateCRC32(data []byte) string

GenerateCRC32

@Description: 生成CRC32校验码
@param data
@return string

func GenerateRandomKey

func GenerateRandomKey(length int) ([]byte, error)

GenerateRandomKey

@Description: 生成指定长度的随机密钥,用于加密或签名等场景
@param length 密钥的长度(字节数)
@return []byte 返回生成的随机密钥
@return error 如果生成失败,返回错误

func HMACSHA256

func HMACSHA256(key []byte, message string) (string, error)

HMACSHA256

@Description: 生成基于密钥的 HMAC-SHA256 签名
@param key 签名密钥
@param message 签名内容
@return string 返回签名的十六进制字符串
@return error

func MD5

func MD5(data []byte) string

MD5

@Description: 生成MD5校验码
@param data
@return string

func RSADecrypt

func RSADecrypt(privKey *rsa.PrivateKey, ciphertext string) ([]byte, error)

RSADecrypt

@Description: RSA私钥解密 @param privKey 私钥 @param ciphertext base64加密的密文 @return []byte 返回解密后的数据 @return error

func RSAEncrypt

func RSAEncrypt(pubKey *rsa.PublicKey, plaintext []byte) (string, error)

RSAEncrypt

@Description: RSA公钥加密 @param pubKey 公钥 @param plaintext 原始数据 @return string 返回加密后的数据 @return error

func SHA256

func SHA256(data []byte) string

SHA256

@Description: 生成SHA256校验码
@param data
@return string

func XXTeaDecrypt

func XXTeaDecrypt(str, key string) string

XXTeaDecrypt

@Description: 带过期时间的解密
@param str
@param key
@return string

func XXTeaEncrypt

func XXTeaEncrypt(str, key string, expiry int) string

XXTeaEncrypt

@Description: 带过期时间的加密
@param str
@param key
@param expiry
@return string

func ZlibCompress

func ZlibCompress(data []byte) ([]byte, error)

func ZlibDecompress

func ZlibDecompress(data []byte) ([]byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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