diff --git a/src/public/js/main.js b/src/public/js/main.js index db95c10..28281e1 100644 --- a/src/public/js/main.js +++ b/src/public/js/main.js @@ -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()); @@ -79,7 +83,6 @@ const send = (file, element) => { * 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 * encoded in the URL */ - }); }); }; diff --git a/src/public/js/rsa.js b/src/public/js/rsa.js index e27dffa..1e9d394 100644 --- a/src/public/js/rsa.js +++ b/src/public/js/rsa.js @@ -35,14 +35,32 @@ const RSA = (msg, key) => { 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); }; -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)]); }; +export const RSA_dec_data = (data, key) => { + let decoded = ""; + data.forEach((piece) => { + decoded += RSA_dec(piece, key); + }); + + return decoded; +}; + const str_to_int = (msg) => { let result = ""; let table = [];