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 OAEP padding #582 #583

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ext/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ function RSAEncrypt(text) {

// Return the PKCS#1 OAEP RSA encryption of "text" as an even-length hex string
function RSAEncryptOAEP(text, hash, hashLen) {
var m = oaep_pad(text, (this.n.bitLength() + 7) >> 3, hash, hashLen);
var n = (this.n.bitLength() + 7) >> 3;
var m = oaep_pad(text, n, hash, hashLen);
if(m == null) return null;
var c = this.doPublic(m);
if(c == null) return null;
var h = c.toString(16);
if((h.length & 1) == 0) return h; else return "0" + h;
while (h.length < n*2) h = "0" + h;
return h;
}

// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
Expand Down