在Dart中使用AES ECB加密二进制数组

问题描述 投票:0回答:1

我正在寻找一种在Dart中加密二进制数组的方法。我已经看过一些比较常见的库,比如https://pub.dartlang.org/packages/encrypt,但是其中很多只能处理字符串形式的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的信息并不多。有没有更好的方法来实现我想要的?

dart flutter pointycastle
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.