PointyCastle / pointycastle

Moved into the Bouncy Castle project: https://github.com/bcgit/pc-dart
MIT License
270 stars 76 forks source link

Problem making JWT using RSA #183

Closed joaoritter closed 5 years ago

joaoritter commented 5 years ago

Bad State: AES engine not initialised

I'm making a JWT using RSA like so:

` final rnd = FortunaRandom();

final rsapars = RSAKeyGeneratorParameters(BigInt.parse("65537"), 2048, 12);
final params = ParametersWithRandom(rsapars, rnd);

final k = RSAKeyGenerator();

k.init(params);

final keyPair = k.generateKeyPair();

final header = _header;
final payload = _payload;
final cipher = RSAEngine()
  ..init(true, PrivateKeyParameter(keyPair.privateKey));

final content = header + "." + payload;

final cipherText = cipher.process(Uint8List.fromList(content.codeUnits));

final signature = String.fromCharCodes(cipherText);

final jwtToken = content + "." + signature;
return jwtToken;

`

What am I missing?? Thanks in advance!

joaoritter commented 5 years ago

Troubleshooting: First problem seems to be with FortunaRandom as the random number input.

joaoritter commented 5 years ago

This article had everything I needed! https://morioh.com/p/6f069be5a287/asymmetric-key-generation-in-flutter

joaoritter commented 5 years ago

original source => https://medium.com/flutter-community/asymmetric-key-generation-in-flutter-ad2b912f3309