网上搜索到的这个解决方案实在是太烂了
https://blog.csdn.net/u013685695/article/details/101528438
https://pub.dev/packages/flutter_aes_ecb_pkcs5
上边的解决方案是与原生做个bridge,使用原生来加解密。
其实直接用Dart原生就行
https://pub.dev/packages/encrypt
上代码
import 'package:encrypt/encrypt.dart' as XYQ;
void main() {
final key = XYQ.Key.fromUtf8('my 32 length key................');
final encrypter = XYQ.Encrypter(XYQ.AES(key, mode: XYQ.AESMode.ecb));
final text =
"A set of high-level APIs over PointyCastle for two-way cryptography.";
final encrypted = encrypter.encrypt(text);
final decrypted = encrypter.decrypt(encrypted);
print(
decrypted); // A set of high-level APIs over PointyCastle for two-way cryptography.
print(encrypted
.base64); // +H8VseqZhaZaK8EUh+K2jlHXBFbRA/dHkpPDf0fN+YaNro9ofBNlLsVtrkmmiulBoBiS4EQE7djVvsouuVyIXwe3lQogMzWcdAULNBSrSRM=
}
网友评论