PointyCastle / pointycastle

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

Failed to decrypt RSA encryption #187

Closed lets-swapcode closed 5 years ago

lets-swapcode commented 5 years ago

Share function code which decrypt a encrypted text using RSA (pointycastle) dart flutter.

lets-swapcode commented 5 years ago

@duncanhoggan can you help now ?

duncanhoggan commented 5 years ago

Hey, sure this is what i use for RSA with PKCS1 padding

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);
  }

static String decrypt(String input, RSAPrivateKey privateKey) {
    var cipher = PKCS1Encoding(RSAEngine());
    cipher.init(false, PrivateKeyParameter<RSAPrivateKey>(privateKey));
    Uint8List output = cipher.process(base64Decode(input));
    return utf8.decode(output);
  }
lets-swapcode commented 5 years ago

Thanks alot. you saved ton of my time.