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) {