我有以下PostgreSQL命令:
select encrypt_iv('test1','테스트2','测试3','aes-cbc');
select convert_from(decrypt_iv('\x8e9a657e13b64f4111ab1668dc0f5747','테스트2','测试3','aes-cbc'),'SQL_ASCII');我试图使用加密包在Dart中复制这些命令:
void main(List<String> args) {
final plainText = 'test1';
final key = Key.fromUtf8('테스트2');
final iv = IV.fromUtf8('测试3');
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print(decrypted);
print(encrypted.bytes);
print(encrypted.base16);
print(encrypted.base64);
}我收到了一条错误消息:
Unhandled exception:
Invalid argument(s): Initialization vector must be the same length as block size
#0 CBCBlockCipher.init (package:pointycastle/block/modes/cbc.dart:52:7)
#1 PaddedBlockCipherImpl.init (package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart:47:12)
#2 AES.encrypt (package:encrypt/src/algorithms/aes.dart:35:9)
#3 Encrypter.encryptBytes (package:encrypt/src/encrypter.dart:12:19)
#4 Encrypter.encrypt (package:encrypt/src/encrypter.dart:20:12)
#5 main (file:///home/userx/Projects/dart/encrypt_example/bin/main.dart:11:31)
#6 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)这个包中缺少帮助,所以我不知道如何正确地使用它。
有人能给我一些关于它的使用的指导或者建议另一个方案吗?
发布于 2021-12-11 07:20:13
初始化向量必须与块大小相同。
因此,AES块大小为128位(16字节)。
PostgreSQL 文档对IV的索赔:
它被裁剪或填充零,如果不是完全块大小。
我想(!)钥匙也是一样的。从安全性和互操作性的角度来看,这是一个糟糕的想法),但我们必须接受它。因此,尝试拥有一个要求长度为零字节的数组,并将较短的IV或键复制到数组中。
下一首
https://stackoverflow.com/questions/70313159
复制相似问题