Skip to content

Fix issue where encrypted data was not decryptable#523

Open
diffidentDude wants to merge 1 commit intodigitalbazaar:mainfrom
diffidentDude:FIX_RSA_OAEP_HSM_BOUNCY_CASTLE
Open

Fix issue where encrypted data was not decryptable#523
diffidentDude wants to merge 1 commit intodigitalbazaar:mainfrom
diffidentDude:FIX_RSA_OAEP_HSM_BOUNCY_CASTLE

Conversation

@diffidentDude
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Member

dlongley commented Jul 12, 2017

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

@diffidentDude
Copy link
Copy Markdown
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.

2 participants