fix rsa implementation
This commit is contained in:
parent
0c12c6b2e6
commit
d57a6ae06a
2 changed files with 25 additions and 4 deletions
|
@ -1,4 +1,8 @@
|
||||||
import { gen_RSA_keypair, RSA_dec, RSA_enc } from "./rsa.js";
|
import {
|
||||||
|
gen_RSA_keypair,
|
||||||
|
RSA_enc_data as RSA_enc,
|
||||||
|
RSA_dec_data as RSA_dec,
|
||||||
|
} from "./rsa.js";
|
||||||
|
|
||||||
window.addEventListener("load", () => main());
|
window.addEventListener("load", () => main());
|
||||||
|
|
||||||
|
@ -79,7 +83,6 @@ const send = (file, element) => {
|
||||||
* When the user click on the link, he can download the file, asking
|
* When the user click on the link, he can download the file, asking
|
||||||
* to the server with the hash of the link and the public key
|
* to the server with the hash of the link and the public key
|
||||||
* encoded in the URL */
|
* encoded in the URL */
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,14 +35,32 @@ const RSA = (msg, key) => {
|
||||||
return modPow(msg, key[0], key[1]);
|
return modPow(msg, key[0], key[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RSA_enc = (data, key) => {
|
const RSA_enc = (data, key) => {
|
||||||
return RSA(str_to_int(data)[0], key);
|
return RSA(str_to_int(data)[0], key);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RSA_dec = (data, key) => {
|
export const RSA_enc_data = (data, key) => {
|
||||||
|
let encoded = [];
|
||||||
|
data.match(/(.{1,100})/g).forEach((piece) => {
|
||||||
|
encoded.push(RSA_enc(piece, key));
|
||||||
|
});
|
||||||
|
|
||||||
|
return encoded;
|
||||||
|
};
|
||||||
|
|
||||||
|
const RSA_dec = (data, key) => {
|
||||||
return int_to_str([RSA(data, key)]);
|
return int_to_str([RSA(data, key)]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const RSA_dec_data = (data, key) => {
|
||||||
|
let decoded = "";
|
||||||
|
data.forEach((piece) => {
|
||||||
|
decoded += RSA_dec(piece, key);
|
||||||
|
});
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
};
|
||||||
|
|
||||||
const str_to_int = (msg) => {
|
const str_to_int = (msg) => {
|
||||||
let result = "";
|
let result = "";
|
||||||
let table = [];
|
let table = [];
|
||||||
|
|
Reference in a new issue