Skip to content

Commit

Permalink
Merge pull request travist#75 from calve/master
Browse files Browse the repository at this point in the history
Fix RSAEncrypt padding
  • Loading branch information
travist authored Jun 21, 2016
2 parents 756aa21 + 4fba242 commit ac23ed5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/jsbn/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function byte2Hex(b) {
return b.toString(16);
}

function pad(value, length) {
return (value.toString().length < length) ? pad("0"+value, length):value;
}

// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
function pkcs1pad2(s,n) {
if(n < s.length + 11) { // TODO: fix for utf-8
Expand Down Expand Up @@ -94,7 +98,7 @@ function RSAEncrypt(text) {
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;
return pad(h, 512);
}

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

0 comments on commit ac23ed5

Please sign in to comment.