Skip to content

Commit

Permalink
Merge pull request #32 from TencentBlueKing/develop
Browse files Browse the repository at this point in the history
v1.0.8
  • Loading branch information
wklken committed Jan 23, 2022
2 parents 6bf264d + 0bb17e7 commit ae3ab21
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 ae3ab21

Please sign in to comment.