Skip to content

Commit

Permalink
Fix OAEP padding
Browse files Browse the repository at this point in the history
  • Loading branch information
davedoesdev committed Apr 14, 2023
1 parent 9671f4b commit 1cfd939
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 1cfd939

Please sign in to comment.