Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart #xA3有什么问题;在加密机中使用时的符号?_Dart - Fatal编程技术网

Dart #xA3有什么问题;在加密机中使用时的符号?

Dart #xA3有什么问题;在加密机中使用时的符号?,dart,Dart,当我根据AES加密机在密码中使用£symbol时,我得到了错误 密钥长度必须为128/192/256位 堆栈跟踪 未处理的异常: Invalid argument(s): Key length must be 128/192/256 bits #0 AESFastEngine.init (package:pointycastle/block/aes_fast.dart:66:7) #1 SICStreamCipher.init (package:pointycastle/st

当我根据AES加密机在密码中使用£symbol时,我得到了错误

密钥长度必须为128/192/256位

堆栈跟踪 未处理的异常:

Invalid argument(s): Key length must be 128/192/256 bits
#0      AESFastEngine.init (package:pointycastle/block/aes_fast.dart:66:7)
#1      SICStreamCipher.init (package:pointycastle/stream/sic.dart:55:22)
#2      StreamCipherAsBlockCipher.init (package:pointycastle/adapters/stream_cipher_as_block_cipher.dart:27:18)
#3      PaddedBlockCipherImpl.init (package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart:43:12)
#4      AES.encrypt (package:encrypt/src/algorithms/aes.dart:19:9)
#5      Encrypter.encryptBytes (package:encrypt/src/encrypter.dart:12:19)
#6      Encrypter.encrypt (package:encrypt/src/encrypter.dart:20:12)
这个包裹被使用了

下面是包
加密
函数

Encrypted encrypt(String input, {IV iv}) {
    return encryptBytes(convert.utf8.encode(input), iv: iv);
}

由于您使用UTF-8表示密码,因此需要考虑到并非所有字母都只能用1字节(8位)表示

例如,
用两个字节(16位)表示:
c2a3

这可以在以下示例中看到:

import 'dart:convert';

void main() {
  print(utf8.encode('my_cool_password_£..............').length * 8); // 264
  print(utf8.encode('my_cool_password_x..............').length * 8); // 256
  print(utf8.encode('£').length * 8); // 16
  print(utf8.encode('£').map((i) => i.toRadixString(16))); // (c2, a3)
}

您是如何发现字符被定义为:c2a3的?您可以使用像:这样的表,也可以通过打印从dart获取它(utf8.encode('英镑').map((i)=>i.toRadixString(16))
import 'dart:convert';

void main() {
  print(utf8.encode('my_cool_password_£..............').length * 8); // 264
  print(utf8.encode('my_cool_password_x..............').length * 8); // 256
  print(utf8.encode('£').length * 8); // 16
  print(utf8.encode('£').map((i) => i.toRadixString(16))); // (c2, a3)
}