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

Fix issue where encrypted data was not decryptable #523

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

diffidentDude
Copy link

We are encrypting on the front end using RSA-OAEP.

const encrypted = key.encrypt(data, 'RSA-OAEP', {
  md: Forge.md.sha256.create(),
  mgf1: {
    md: Forge.md.sha256.create()
  }
});

We found that we were not able to decrypt with either bouncy castle or the HSM.

After debugging with forge and bouncy castle side by side we found this was the only difference between the libraries.

We are encrypting on the front end using RSA-OAEP. 
    const encrypted = key.encrypt(data, 'RSA-OAEP', {
      md: Forge.md.sha256.create(),
      mgf1: {
        md: Forge.md.sha256.create()
      }
    });

We found that we were not able to decrypt with either bouncy castle or the HSM. This resolved the issue for us.
@dlongley
Copy link
Member

dlongley commented Jul 12, 2017

Prepending the leading 0x00 byte is correct according to PKCS#1 v2.1. This is a change from 2.0, but it should be backwards compatible. So the patch in this PR would not be correct -- there must be some other issue with forge, bouncy castle, or the application. We can't rule out a bug with forge or bouncy castle, but the most likely source of the bug is usually the application, as many others are using both forge and bouncy castle RSA-OAEP without issue.

https://crypto.stackexchange.com/questions/40032/why-did-oaep-change-from-pkcs1-v2-0-and-v2-1

@dlongley
Copy link
Member

dlongley commented Jul 12, 2017

The latest, PKCS#1 v2.2, also prepends a 0x00 byte to the encoded message.

@diffidentDude
Copy link
Author

Cheers for the feedback, we'll do some more investigation and get back to you.

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

Successfully merging this pull request may close these issues.

None yet

2 participants