Sign packets
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { generate_keypair } from "./paillier.js";
|
||||
import { generate_rsa_keypair } from "./rsa.js";
|
||||
import { generate_rsa_keypair, RsaPubKey } from "./rsa.js";
|
||||
|
||||
export { generate_keypair, generate_rsa_keypair };
|
||||
export { generate_keypair, generate_rsa_keypair, RsaPubKey };
|
||||
|
@ -3,18 +3,29 @@ import { mod_exp, mod_inv } from "./math.js";
|
||||
|
||||
let p, q, pubKey, privKey;
|
||||
|
||||
class PubKey {
|
||||
constructor(p, q) {
|
||||
this.n = p * q;
|
||||
this.e = 65537n;
|
||||
export class RsaPubKey {
|
||||
constructor(n, e) {
|
||||
this.n = n;
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
encrypt(m) {
|
||||
return mod_exp(m, this.e, this.n);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
n: "0x" + this.n.toString(16),
|
||||
e: "0x" + this.e.toString(16),
|
||||
};
|
||||
}
|
||||
|
||||
static fromJSON(data) {
|
||||
return new RsaPubKey(BigInt(data.n), BigInt(data.e));
|
||||
}
|
||||
}
|
||||
|
||||
class PrivKey {
|
||||
class RsaPrivKey {
|
||||
constructor(p, q) {
|
||||
this.n = p * q;
|
||||
this.d = mod_inv(65537n, (q - 1n) * (p - 1n));
|
||||
@ -40,8 +51,8 @@ export function generate_rsa_keypair() {
|
||||
q = BigInt(window.sessionStorage.getItem("rsa_q"));
|
||||
}
|
||||
|
||||
pubKey = new PubKey(p, q);
|
||||
privKey = new PrivKey(p, q);
|
||||
pubKey = new RsaPubKey(p * q, 65537n);
|
||||
privKey = new RsaPrivKey(p, q);
|
||||
|
||||
return { pubKey, privKey };
|
||||
}
|
||||
|
Reference in New Issue
Block a user