flutter
run() {
//printInfo(info: "=============");
//var aesEncodeString = aesEncode("123456");
//printInfo(info: aesEncodeString);
//
var aesDecodeString = aesDecode("Twy3VnIxPEK7aLdisvOFVg==");
printInfo(info: aesDecodeString);
}
//aes加密
String aesEncode(String content) {
try {
final key = Key.fromUtf8("8888888888888888");
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted = encrypter.encrypt(content, iv: IV.fromUtf8("8888888888888888"));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//aes解密
dynamic aesDecode(dynamic base64) {
try {
final key = Key.fromUtf8("8888888888888888");
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
return encrypter.decrypt64(base64, iv: IV.fromUtf8("8888888888888888"));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
golang
import (
"encoding/base64"
"fmt"
"github.com/forgoer/openssl"
)
func main() {
src := []byte("123456")
key := []byte("8888888888888888")
iv := []byte("8888888888888888")
dst, _ := openssl.AesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)
fmt.Println(base64.StdEncoding.EncodeToString(dst)) // 1jdzWuniG6UMtoa3T6uNLA==
dst, _ = openssl.AesCBCDecrypt(dst, key, iv, openssl.PKCS7_PADDING)
fmt.Println(string(dst)) // 123456
}