Documentation
¶
Overview ¶
Package cryptutils 提供加密解密相关的工具函数
Index ¶
- func AESDecrypt(ciphertext, key []byte) ([]byte, error)
- func AESEncrypt(plaintext, key []byte) ([]byte, error)
- func Base64Decode(encoded string) ([]byte, error)
- func Base64Encode(data []byte) string
- func GenerateRandomBytes(length int) ([]byte, error)
- func GenerateRandomHex(length int) (string, error)
- func GenerateRandomString(length int, charset string) (string, error)
- func GenerateUUID() (string, error)
- func GenerateUUIDWithoutHyphens() (string, error)
- func MD5Hash(data []byte) string
- func SHA1Hash(data []byte) string
- func SHA256Hash(data []byte) string
- func SHA512Hash(data []byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
AESDecrypt 使用AES-GCM模式解密数据 参数:
- ciphertext: 要解密的密文数据 (包含nonce)
- key: 解密密钥 (必须是16, 24或32字节长,对应AES-128, AES-192或AES-256)
返回:
- []byte: 解密后的明文数据
- error: 如果解密失败则返回错误信息
func AESEncrypt ¶
AESEncrypt 使用AES-GCM模式加密数据 参数:
- plaintext: 要加密的明文数据
- key: 加密密钥 (必须是16, 24或32字节长,对应AES-128, AES-192或AES-256)
返回:
- []byte: 加密后的数据 (包含随机生成的nonce)
- error: 如果加密失败则返回错误信息
func Base64Decode ¶
Base64Decode 解码Base64字符串 参数:
- encoded: Base64编码的字符串
返回:
- []byte: 解码后的数据
- error: 如果解码失败则返回错误信息
func GenerateRandomBytes ¶
GenerateRandomBytes 生成指定长度的随机字节 参数:
- length: 要生成的随机字节长度
返回:
- []byte: 生成的随机字节
- error: 如果生成失败则返回错误信息
func GenerateRandomHex ¶
GenerateRandomHex 生成指定长度的随机十六进制字符串 参数:
- length: 要生成的十六进制字符串长度(字节数的两倍)
返回:
- string: 生成的十六进制字符串
- error: 如果生成失败则返回错误信息
func GenerateRandomString ¶
GenerateRandomString 生成指定长度的随机字符串 参数:
- length: 要生成的字符串长度
- charset: 字符集(如果为空,则使用默认字符集)
返回:
- string: 生成的随机字符串
- error: 如果生成失败则返回错误信息
func GenerateUUIDWithoutHyphens ¶
GenerateUUIDWithoutHyphens 生成一个没有连字符的UUID 返回:
- string: 生成的UUID字符串(无连字符)
- error: 如果生成失败则返回错误信息
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.