1.PHP下的AES加解密
//aes加密function aes_encode($message){ return openssl_encrypt($message,"AES-256-CBC","这里须要32位长的密钥英文",0 ,"这里须要16位长的初始向量英文");}//aes解密function aes_decode($encodeData){ return openssl_decrypt($encodeData,"AES-256-CBC","这里须要32位长的密钥英文",0,"这里须要16位长的初始向量英文");}
2.FLUTTER在的AES加解密
import 'package:encrypt/encrypt.dart';class AESUTIL { //aes解密 static String decode(String data) { final key = Key.fromUtf8('这里须要32位长的密钥英文'); final iv = IV.fromUtf8("这里须要16位长的初始向量英文"); final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); final decrypted = encrypter.decrypt(Encrypted.from64(data), iv: iv); return decrypted; } //aes加密 static String encode(String data) { final key = Key.fromUtf8('这里须要32位长的密钥英文'); final iv = IV.fromUtf8("这里须要16位长的初始向量英文"); final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); final encrypted = encrypter.encrypt(data, iv: iv); return encrypted.base64; }}
32位的英文密钥,16位的初始向量都是自己指定的。
在php端进行数据加密后,可以在flutter端进行解密。