Uint64List not supported on flutter web

425 Views Asked by At

i have an error with Uint64List in flutter Web (in 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

Do you know how to fix that ? Thx

2

There are 2 best solutions below

0
Richard Heap On BEST ANSWER

For all practical values of IV length, you can fit the value in a 32 bit int. The following equivalent code runs fine in Dartpad and gives the same result as the above code in VM.

import 'dart:typed_data';

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

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

  print(length);
}

And, similarly, this:

var len = Uint8List.view((Uint32List(4)
      ..[2] = aad!.length * 8
      ..[0] = _processedBytes * 8)
    .buffer);
1
redDwarf On

Thx And about please ?

 @override
  int doFinal(Uint8List out, int outOff) {
    var result = remainingInput.isNotEmpty
        ? processBlock(remainingInput, 0, out, outOff)
        : 0;

    var len = Uint8List.view((Uint64List(2)
          ..[1] = aad!.length * 8
          ..[0] = _processedBytes * 8)
        .buffer);
    len = Uint8List.fromList(len.reversed.toList());

    _gHASHBlock(_x, len);

    _xor(_x, _e0);

    if (forEncryption) {
      out.setAll(outOff + result, _x);
      result += _x.length;
    }

    validateMac();

    return result;
  }