Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMIME decryption issue #204

Open
ahsentanvir opened this issue Aug 31, 2023 · 0 comments
Open

SMIME decryption issue #204

ahsentanvir opened this issue Aug 31, 2023 · 0 comments

Comments

@ahsentanvir
Copy link

ahsentanvir commented Aug 31, 2023

I am trying to decrypt an SMIME encrypted email as received from an exchange server. The code block that I am using is derived from the example section of this repo -

String rsaDecrypt(RSAPrivateKey myPrivate, Uint8List cipherText) {
  final decryptor = RSAEngine()
    ..init(false, PrivateKeyParameter<RSAPrivateKey>(myPrivate));

  return String.fromCharCodes(_processInBlocks(decryptor, cipherText));
}

Uint8List _processInBlocks(AsymmetricBlockCipher engine, Uint8List input) {
  final numBlocks = input.length ~/ engine.inputBlockSize +
      ((input.length % engine.inputBlockSize != 0) ? 1 : 0);

  final output = Uint8List(numBlocks * engine.outputBlockSize);

  var inputOffset = 0;
  var outputOffset = 0;
  while (inputOffset < input.length) {
    final chunkSize = (inputOffset + engine.inputBlockSize <= input.length)
        ? engine.inputBlockSize
        : input.length - inputOffset;

    outputOffset += engine.processBlock(
        input, inputOffset, chunkSize, output, outputOffset);

    inputOffset += chunkSize;
  }

  return (output.length == outputOffset)
      ? output
      : output.sublist(0, outputOffset);
}

I am passing the right parameters to rsaDecrypt() method. i.e. the private key and Uint8List representation of mimeContent of the email. I have verified that private key & mimecontent is correct as the same work well for decryption using bouncycastle in java.

But I am unable to decrypt the email using this library in flutter and some garbage values are output. Any clues guys? Or is it like this flutter library is not mature enough to handle SMIME decryption?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant