bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
241 stars 125 forks source link

[RSA/OEAP]: Invalid argument(s): message too long #212

Closed Ahmadre closed 1 year ago

Ahmadre commented 1 year ago

Error

I try to encrypt asymmetric with the publicKey and I get on longer bytes this:

flutter: Invalid argument(s): message too long
flutter: 
#0      OAEPEncoding._encodeBlock (package:pointycastle/asymmetric/oaep.dart:196:7)
#1      OAEPEncoding.processBlock (package:pointycastle/asymmetric/oaep.dart:167:14)

I call it like:

  String asymmetricEncrypt({
    Uint8List bytes,
  }) {
    const pem =
        '-----BEGIN PUBLIC KEY-----\n${PBKey}\n-----END PUBLIC KEY-----\n';
    final publicKey = CryptoUtils.rsaPublicKeyFromPem(pem);

    /// Initalizing Cipher
    final cipher = OAEPEncoding.withSHA256(AsymmetricBlockCipher('RSA'));
    cipher.init(true, PublicKeyParameter<RSAPublicKey>(publicKey));

    Uint8List output = cipher.process(bytes!);
    return base64Encode(output);
  }

Do you know how i can pass longer bytes? In my case I am passing the bytes of a Textfile.