diff --git a/crypto/aes.go b/crypto/aes.go index 9c29830..1bd1d89 100644 --- a/crypto/aes.go +++ b/crypto/aes.go @@ -4,6 +4,8 @@ import ( "bytes" "crypto/aes" "crypto/cipher" + + "github.com/Luzifer/go-openssl/v3" ) func paddingPKCS7(ciphertext []byte, blockSize int) []byte { @@ -45,3 +47,27 @@ func DecryptAES(ciphertext, key, iv []byte) ([]byte, error) { origData = unpaddingPKCS7(origData) return origData, nil } + +// DecryptAESWithOpenSSL 使用Openssl 解密AES +func DecryptAESWithOpenSSL(value, key string) ([]byte, error) { + o := openssl.New() + + dec, err := o.DecryptBytes(key, []byte(value), openssl.DigestMD5Sum) + if err != nil { + return nil, err + } + + return dec, nil +} + +// EncryptAESWithOpenSSL 使用Openssl 加密AES +func EncryptAESWithOpenSSL(value, key string) ([]byte, error) { + o := openssl.New() + + enc, err := o.EncryptBytes(key, []byte(value), openssl.DigestMD5Sum) + if err != nil { + return nil, err + } + + return enc, nil +} diff --git a/go.mod b/go.mod index db887a9..ee8cc68 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.simts.cc/common/lib go 1.17 require ( + github.com/Luzifer/go-openssl/v3 v3.1.0 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/mojocn/base64Captcha v1.3.1 go.uber.org/zap v1.15.0 diff --git a/go.sum b/go.sum index 6e6b58b..16f1ba0 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw= +github.com/Luzifer/go-openssl/v3 v3.1.0/go.mod h1:liy3FXuuS8hfDlYh1T+l78AwQ/NjZflJz0NDvjKhwDs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=