Skip to content

Commit

Permalink
Merge pull request #31 from wklken/ft_1.0.8
Browse files Browse the repository at this point in the history
Ft 1.0.8
  • Loading branch information
wklken authored Jan 23, 2022
2 parents 1fc4b77 + 7119a19 commit 0bb17e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cryptography/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
### aes_gcm

```go
import "github.com/TencentBlueKing/gopkg/cryptography"

const (
cryptoKey = "C4QSNKR4GNPIZAH3B0RPWAIV29E7QZ66"
aesGcmNonce = "KC9DvYrNGnPW"
Expand All @@ -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)
```
2 changes: 1 addition & 1 deletion cryptography/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0bb17e7

Please sign in to comment.