我正在寻找一种在Dart中加密二进制数组的方法。我看过一些更常见的库,例如https://pub.dartlang.org/packages/encrypt,但是其中许多库只能处理String形式的AES密钥和数据,而不能处理二进制数组。
我也看过了https://github.com/PointyCastle/pointycastle,它似乎能够处理二进制数组中的AES密钥和数据,但是我还不太清楚如何正确使用它。包含数据的二进制数组的长度始终与键相同,因此不需要任何填充。
到目前为止,这是我的代码:
class Encr {
static List<int> encrCmd(List<int> inputData, List<int> aesKey) {
Uint8List keyList = Uint8List.fromList(aesKey);
Uint8List dataList = Uint8List.fromList(inputData);
CipherParameters cip = new PaddedBlockCipherParameters(newKeyParameter(keylist), null);
BlockCipher cipherImpl = new BlockCipher("AES/ECB");
cipherImpl.init(true, cip);
Uint8List encrypted = cipherImpl.process(dataList);
print("encrypted data: " + encrypted.toString());
}
}
这将导致以下错误消息:
I/flutter (55555): The following assertion was thrown while handling a gesture:
I/flutter (55555): type 'PaddedBlockCipherParameters<KeyParameter, Null>' is not a subtype of type 'KeyParameter' of 'params'
不幸的是,关于如何使用PointyCastle的信息并不多。也许有更好的方法来实现我想要的?
答案 0 :(得分:1)
您不需要img.controlsAboveOverlay = false
,因为您没有使用填充密码。
尝试:
canvas.controlsAboveOverlay = false