From 38722d9b5c1fe5429cf6e6e1b0b9a22a0a07fc9e Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 23 Jan 2022 14:19:07 +0800 Subject: [PATCH 1/2] fix(cryptography): interface func wrong --- cryptography/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/types.go b/cryptography/types.go index b8062b3..57f3c25 100644 --- a/cryptography/types.go +++ b/cryptography/types.go @@ -15,6 +15,6 @@ type Crypto interface { Encrypt(plaintext []byte) []byte Decrypt(encryptedText []byte) ([]byte, error) - EncryptToString(plaintext []byte) (string, error) + EncryptToString(plaintext []byte) string DecryptString(encryptedText string) ([]byte, error) } From 7119a19d385d8a42b4b2420c0edb2d999bf980ea Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 23 Jan 2022 14:23:44 +0800 Subject: [PATCH 2/2] docs(cryptography/readme.md): update --- cryptography/readme.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cryptography/readme.md b/cryptography/readme.md index f8942e3..b407020 100644 --- a/cryptography/readme.md +++ b/cryptography/readme.md @@ -7,6 +7,8 @@ ### aes_gcm ```go +import "github.com/TencentBlueKing/gopkg/cryptography" + const ( cryptoKey = "C4QSNKR4GNPIZAH3B0RPWAIV29E7QZ66" aesGcmNonce = "KC9DvYrNGnPW" @@ -17,13 +19,13 @@ if err != nil { return nil, fmt.Errorf("cryptos key error: %w", err) } -plain := "hello world" +plain := []byte("hello world") // plain cs := c.Encrypt(plain) ds, err := c.Decrypt(cs) // base64 -cs1 := c.EncryptToBase64([]bytes(plain)) -ds1, err = c.DecryptFromBase64(cs1) +cs1 := c.EncryptToString(plain) +ds1, err := c.DecryptString(cs1) ```