Throw BadPaddingException on RSA decrypt failures#216
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR aligns WolfCryptCipher RSA decrypt error handling with JCE Cipher expectations by mapping native RSA decrypt failures to JCE exceptions and adding regression tests for wrong-key decrypt paths.
Changes:
- Map RSA OAEP and PKCS#1 decrypt failures to
BadPaddingExceptioninstead of propagatingWolfCryptException. - Add RSA decrypt input-length checks intended to throw
IllegalBlockSizeExceptionwhen ciphertext length doesn’t match the modulus size. - Add JUnit regression tests covering wrong-key decrypt scenarios and tighten existing “too big data” expectations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java | Adds RSA ciphertext length checks and remaps native decrypt errors to BadPaddingException. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java | Adds regression tests and test vectors for wrong-key RSA decrypt; updates expectations for oversize input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
caa979a to
0da3d08
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #216
Scan targets checked: wolfcrypt-jni-bugs, wolfcrypt-jni-src
No new issues found in the changed files. ✅
rlm2002
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes RSA decrypt exception handling in
WolfCryptCipherto match expected JCE Cipher behavior:javax.crypto.BadPaddingExceptiononRSA/ECB/PKCS1PaddingandRSA/ECB/OAEP*decrypt failures, instead of propagating aWolfCryptException.IllegalBlockSizeExceptionwhen RSA decrypt input length does not match the modulus size.Includes JUnit tests to prevent regression.