From 1cdf6cb507e938f125324de0ce21d04c6655ff6b Mon Sep 17 00:00:00 2001 From: jiangyong Date: Thu, 18 Jun 2026 09:14:18 +0800 Subject: [PATCH] Encrypt --- encoding.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/encoding.go b/encoding.go index 8bcba1f..620ad7a 100644 --- a/encoding.go +++ b/encoding.go @@ -66,38 +66,38 @@ func DecryptID(data, salt string) int64 { } // 先压缩再加密(适合长文本) -func Encrypt(plaintext string, key string) (string, error) { +func Encrypt(plaintext string, key string) string { // 1. 压缩 var buf bytes.Buffer gz := gzip.NewWriter(&buf) if _, err := gz.Write([]byte(plaintext)); err != nil { - return "", err + return "" } if err := gz.Close(); err != nil { - return "", err + return "" } compressed := buf.Bytes() // 2. 加密(使用AES-GCM) block, err := aes.NewCipher([]byte(Md5(key))) if err != nil { - return "", err + return "" } gcm, err := cipher.NewGCM(block) if err != nil { - return "", err + return "" } nonce := make([]byte, gcm.NonceSize()) if _, err := io.ReadFull(rand.Reader, nonce); err != nil { - return "", err + return "" } ciphertext := gcm.Seal(nonce, nonce, compressed, nil) // 使用RawURLEncoding - return base64.RawURLEncoding.EncodeToString(ciphertext), nil + return base64.RawURLEncoding.EncodeToString(ciphertext) } func Decrypt(encoded string, key string) (string, error) {