|
|
@ -4,6 +4,8 @@ import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/cipher"
|
|
|
|
"crypto/cipher"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Luzifer/go-openssl/v3"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func paddingPKCS7(ciphertext []byte, blockSize int) []byte {
|
|
|
|
func paddingPKCS7(ciphertext []byte, blockSize int) []byte {
|
|
|
@ -45,3 +47,27 @@ func DecryptAES(ciphertext, key, iv []byte) ([]byte, error) {
|
|
|
|
origData = unpaddingPKCS7(origData)
|
|
|
|
origData = unpaddingPKCS7(origData)
|
|
|
|
return origData, nil
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|