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) ``` 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) }