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 decrypt error with pkcs1 padding #45

Merged
merged 1 commit into from
Nov 14, 2022
Merged

Fix decrypt error with pkcs1 padding #45

merged 1 commit into from
Nov 14, 2022

Conversation

janispritzkau
Copy link
Contributor

I am no expert in RSA cryptography, but was able to fix this issue by trial and error.

I found that the rsa_pkcs1_decrypt function sometimes throws a decryption error, particularly when the h variable in the rsadp function is negative. Switching the remainder operation to modulo seems to fix the problem. And all tests still work.

Should also fix issue #35.

Switched from remainder to modulo operation to always get a positive integer.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@janispritzkau
Copy link
Contributor Author

I would appreciate if this could be merged, even if this library is no longer maintained. I think there is still a need for third party crypto libraries as the web crypto API won't support older or unsecure encryption algorithms like RSA PKCS1 encryption/decryption or AES-128-CFB8.

@invisal invisal merged commit fd9af92 into invisal:master Nov 14, 2022
@invisal
Copy link
Owner

invisal commented Nov 14, 2022

Yes. I have merged the PR. Thanks for contribute. I was thinking of re-maintain it again as I have a bit more free time lately.

@janispritzkau
Copy link
Contributor Author

You're welcome. I decided to re-implement the rsa pkcs1 encryption for my project anyway. A little trick I used is the jwk option in crypto.subtle.exportKey to avoid implementing the asn.1 ber encoding. (https://gist.github.com/janispritzkau/64b3cf0cd77978d269b2e59f5451c6a5)

Another issue in your implementation is a missing message length check in the pkcs1 encrypt function.

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