此包可用于加密/解密流式数据(例如 HTTP、IO 等)
此包最初提供了一个用于 Dio 库的 http 客户端适配器。
安全文件
示例
final secureFile = SecureFile( File('example'), encrypter: encrypter, decrypter: decrypter, useBase64: true, maxBlockSize: 4096, );支持:
Stream<Uint8List>读/写Uint8List读/写String读/写注意事项:
解/加密在读/写时进行,意味着数据将在读取/写入该部分数据之前才解/加密。
解/加密器都使用相同的方法。注意:对于 AES、RSA、Gzip、NoEncryption 等内部加密器,它有一个断言,但如果您扩展 De/Encrypter,您需要先在您的应用程序中测试它。在某些情况下,这看起来没问题,但在读取文件内容时可能会导致错误甚至数据损坏。
此包不扩展
File类。
write方法支持追加到文件。但在此情况下,您需要在构造函数中传入一个EncryptStreamMeta,并使用EncryptStreamMeta.sameSeparatorAsEnding('....... separator .......')将Separator和Ending设置为相同的值。由于某些算法在解/加密过程中负载很高,此类不支持同步读/写。
此类中的方法不在单独的 isolate 中运行,因此可能会导致性能问题。
DioHttpAdapter
/// create instance of `CipherDioHttpAdapter` final dioClient = CipherDioHttpAdapter( decrypter: decrypter, encrypter: encrypter, ); /// creating an instance of `Dio` with `CipherDioHttpAdapter` final dio = Dio()..httpClientAdapter = dioClient;
在此方法中,只有请求的正文被加密。
在此方法中,只有响应的正文被解密。
请求头未加密。要修改请求头,您可以扩展
IByteDataEncrypter的一个类并重写alterHeader方法来实现。
对于后端,您可以查看此项目的示例
解/加密器示例
创建解/加密器实例
final encrypter = AESByteDataEncrypter.randomSecureKey(); final decrypter = AESByteDataDecrypter( key: encrypter.key, iv: encrypter.iv, );