Skip to content

SMIME decryption issue #204

Open
Open

Description

@ahsentanvir

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions