Skip to content

Commit

Permalink
Merge pull request #583 from davedoesdev/master
Browse files Browse the repository at this point in the history
Fix OAEP padding #582
  • Loading branch information
kjur committed Apr 15, 2023
2 parents 9671f4b + 1cfd939 commit d332357
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit d332357

Please sign in to comment.