fix rsa implementation

This commit is contained in:
Mylloon 2022-10-27 13:51:57 +02:00
parent 0c12c6b2e6
commit d57a6ae06a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 25 additions and 4 deletions

View file

@ -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 */
});
});
};

View file

@ -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 = [];