【问题标题】:Uint64List not supported on flutter webFlutter Web 不支持 Uint64List
【发布时间】:2022-11-22 08:46:35
【问题描述】:

我在 flutter Web 中遇到 Uint64List 错误(在 pointycastle lib 中)

var length = Uint8List.view((Uint64List(2)..[0] = iv.length * 8).buffer);

"Error: Unsupported operation: Uint64List not supported on the web.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/typed_data_patch.dart 115:5       new
packages/pointycastle/block/modes/gcm.dart 81:36                              [_computeInitialCounter]
packages/pointycastle/block/modes/gcm.dart 61:16                              prepare
packages/pointycastle/src/impl/base_aead_block_cipher.dart 217:5              reset
packages/pointycastle/block/modes/gcm.dart 47:11                              reset
packages/pointycastle/src/impl/base_aead_block_cipher.dart 117:5              init
packages/pointycastle/block/modes/gcm.dart 40:11                              init
packages/crypto_keys/src/symmetric_operator.dart 71:16                        encrypt

你知道怎么解决吗? 谢谢

【问题讨论】:

  • 如果您需要为 VM 和 Web 使用可移植的 64 位数字(但牺牲速度),请使用 package:fixnum
  • 这在网络上行不通。您可以使用 Uint32List(4).. 等轻松地重写它(然后提交 PR 并关闭您自己的问题)

标签: flutter flutter-web pointycastle


【解决方案1】:

对于 IV 长度的所有实际值,您可以将值放入 32 位 int 中。以下等效代码在 Dartpad 中运行良好,并给出与上述代码在 VM 中相同的结果。

import 'dart:typed_data';

void main() {
  final iv = Uint8List(12);

  final length = Uint8List.view((Uint32List(4)..[0] = iv.length * 8).buffer);

  print(length);
}

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 2020-08-06
    • 2021-08-06
    • 2021-07-06
    • 2019-10-09
    • 2021-07-02
    • 2020-02-16
    • 2022-08-18
    • 2021-01-25
    相关资源
    最近更新 更多