gpt4 book ai didi

dart - 带有尖头城堡SecureRandom()的“AES engine not initialised”

转载 作者:行者123 更新时间:2023-12-03 04:38:41 24 4
gpt4 key购买 nike

我想生成一个具有动态长度位的随机BigInt。我正在使用pointycaSTLe软件包来获取SecureRandom BigInt。

import 'package:pointycastle/pointycastle.dart';

void main(List<String> arguments) {
print(gen(500));
}

BigInt gen(int Bits) {
var n = BigInt.from(1);
var ran = SecureRandom('Fortuna');
n = ran.nextBigInteger(Bits);
return n;
}
这行抛出异常:
n = ran.nextBigInteger(Bits);
StateError (Bad state: AES engine not initialised)
这是控制台中的完整错误:
Unhandled exception:
Bad state: AES engine not initialised
#0 AESFastEngine.processBlock
package:pointycastle/block/aes_fast.dart:109
#1 BlockCtrRandom.nextUint8
package:pointycastle/random/block_ctr_random.dart:55
#2 SecureRandomBase._randomBits
package:pointycastle/…/impl/secure_random_base.dart:55

#3 SecureRandomBase.nextBigInteger
package:pointycastle/…/impl/secure_random_base.dart:33
#4 AutoSeedBlockCtrRandom.nextBigInteger.<anonymous closure>
package:pointycastle/random/auto_seed_block_ctr_random.dart:69
#5 AutoSeedBlockCtrRandom._autoReseedIfNeededAfter
package:pointycastle/random/auto_seed_block_ctr_random.dart:81
#6 AutoSeedBlockCtrRandom.nextBigInteger
package:pointycastle/random/auto_seed_block_ctr_random.dart:68
#7 FortunaRandom.nextBigInteger
package:pointycastle/random/fortuna_random.dart:46
#8 gen
bin\encrypt.dart:10
#9 main
bin\encrypt.dart:4
#10 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)


我似乎在其他任何地方都找不到针对此错误消息的解决方案。我希望你们能帮助我。 :D

最佳答案

尚不清楚,但如果我查看项目中的示例,似乎您需要调用seed方法。以下对我有用:

import 'dart:math';
import 'dart:typed_data';

import 'package:pointycastle/pointycastle.dart';

void main(List<String> arguments) {
print(gen(500));
}

BigInt gen(int bits) {
final _sGen = Random.secure();
var n = BigInt.from(1);
var ran = SecureRandom('Fortuna');
ran.seed(KeyParameter(
Uint8List.fromList(List.generate(32, (_) => _sGen.nextInt(255)))));
n = ran.nextBigInteger(bits);
return n;
}
我受到启发的示例: https://github.com/PointyCastle/pointycastle/blob/master/tutorials/examples/import-demo/import-demo-1.dart

关于dart - 带有尖头城堡SecureRandom()的“AES engine not initialised”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63630661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com