encryption

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

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

AESDecrypt 使用 AES-GCM 解密

func AESDecryptString

func AESDecryptString(ciphertext, key string) (string, error)

AESDecryptString 解密 Base64 编码的密文

func AESEncrypt

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

AESEncrypt 使用 AES-GCM 加密

func AESEncryptString

func AESEncryptString(plaintext, key string) (string, error)

AESEncryptString 加密字符串并返回 Base64 编码

func Base64Decode

func Base64Decode(encoded string) ([]byte, error)

Base64Decode Base64 解码

func Base64Encode

func Base64Encode(data []byte) string

Base64Encode Base64 编码

func Base64URLDecode

func Base64URLDecode(encoded string) ([]byte, error)

Base64URLDecode URL 安全的 Base64 解码

func Base64URLEncode

func Base64URLEncode(data []byte) string

Base64URLEncode URL 安全的 Base64 编码

func CheckPassword

func CheckPassword(password, hash string) bool

CheckPassword 验证密码

func DeriveKey

func DeriveKey(password, salt string, keyLen int) []byte

DeriveKey 从密码派生密钥(简单版本)

func GenerateHexKey

func GenerateHexKey(length int) (string, error)

GenerateHexKey 生成十六进制格式的随机密钥

func GenerateKey

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

GenerateKey 生成指定长度的随机密钥

func GenerateSalt

func GenerateSalt(length int) (string, error)

GenerateSalt 生成盐值

func GetMD5ByStr

func GetMD5ByStr(str string) string

GetMD5ByStr 获取字符串的 MD5 哈希 - CasaOS 兼容别名

func GetMD5FromFile

func GetMD5FromFile(filePath string) (string, error)

GetMD5FromFile 获取文件的 MD5 哈希 - CasaOS 兼容别名

func HMACSHA256

func HMACSHA256(message, secret string) string

HMACSHA256 使用 HMAC-SHA256 签名

func HMACSHA512

func HMACSHA512(message, secret string) string

HMACSHA512 使用 HMAC-SHA512 签名

func HashPassword

func HashPassword(password string) (string, error)

HashPassword 使用 bcrypt 哈希密码

func HashPasswordWithCost

func HashPasswordWithCost(password string, cost int) (string, error)

HashPasswordWithCost 使用指定强度哈希密码

func MD5

func MD5(text string) string

MD5 计算字符串的 MD5 哈希

func MD5Bytes

func MD5Bytes(data []byte) string

MD5Bytes 计算字节数组的 MD5 哈希

func MD5File

func MD5File(filepath string) (string, error)

MD5File 计算文件的 MD5 哈希

func MaskString

func MaskString(s string, visibleStart, visibleEnd int) string

MaskString 遮掩字符串(如密码、密钥)

func PadPKCS7

func PadPKCS7(data []byte, blockSize int) []byte

PadPKCS7 PKCS7 填充

func SHA256

func SHA256(text string) string

SHA256 计算字符串的 SHA256 哈希

func SHA256Bytes

func SHA256Bytes(data []byte) string

SHA256Bytes 计算字节数组的 SHA256 哈希

func SHA256File

func SHA256File(filepath string) (string, error)

SHA256File 计算文件的 SHA256 哈希

func SHA512

func SHA512(text string) string

SHA512 计算字符串的 SHA512 哈希

func SecureCompare

func SecureCompare(a, b string) bool

SecureCompare 安全比较,防止时序攻击

func UnpadPKCS7

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

UnpadPKCS7 移除 PKCS7 填充

func VerifyHMAC

func VerifyHMAC(message, secret, signature string) bool

VerifyHMAC 验证 HMAC 签名

func XOR

func XOR(a, b []byte) []byte

XOR 对两个字节数组进行异或操作

Types

This section is empty.

Jump to

Keyboard shortcuts

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