Skip to content

Commit

Permalink
Fix decrypt error with pkcs1 padding
Browse files Browse the repository at this point in the history
Switched from remainder to modulo operation to always get a positive integer.
  • Loading branch information
janispritzkau committed Nov 7, 2022
1 parent 0544b74 commit 450aebc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rsa/rsa_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function rsadp(key: RSAKey, c: bigint): bigint {
if (m1 >= m2) {
h = (key.qi * (m1 - m2)) % key.p;
} else {
h = (key.qi * (m1 - m2 + key.p * (key.p / key.q))) % key.p;
h = ((key.qi * (m1 - m2 + key.p * (key.p / key.q))) % key.p + key.p) %
key.p;
}

return (m2 + h * key.q) % (key.q * key.p);
Expand Down

0 comments on commit 450aebc

Please sign in to comment.