0

I'm writing some code to encrypt data from a flutter client and send it to our servers. We are using PKCS1 padded RSA but i get the error below when attempting to encrypt the data.

I/flutter (12394): Bad state: Reflectable has not been initialized.
I/flutter (12394): Please make sure that the first action taken by your program
I/flutter (12394): in `main` is to call `initializeReflectable()`.

The code responsible for this is as follows.

static String encrypt(String text, RSAPublicKey pubKey) {
    var cipher = PKCS1Encoding(RSAEngine());
    cipher.init(true, PublicKeyParameter<RSAPublicKey>(pubKey));
    Uint8List output1 = cipher.process(utf8.encode(text));
    return base64Encode(output1);
}

I've managed to get a non padded sample running fine but the PKCS1 padded encryption requires a random generator that is initialized through reflection and flutter is saying no.

Any help would be appreciated.

Duncan Hoggan
  • 5,082
  • 3
  • 23
  • 29

1 Answers1

1

The reflection based Random constructor has been replaced with FortunaRandom and seeded.

_random = new FortunaRandom();
_random.seed(KeyParameter(_seed()));

The PR has been approved and is in master now so no one should have this issue ever again!

Duncan Hoggan
  • 5,082
  • 3
  • 23
  • 29