From 26b3ba9b4a342af008a66087e88628d854226645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20B=C3=BClow?= Date: Tue, 3 Jan 2023 21:42:19 +0100 Subject: [PATCH] now successfully encrypts a file --- src/lib/EncryptButton.svelte | 4 +++- src/lib/cryptlib.ts | 4 ++-- src/lib/generalStore.ts | 3 +++ src/lib/pwgen.ts | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/lib/generalStore.ts diff --git a/src/lib/EncryptButton.svelte b/src/lib/EncryptButton.svelte index 856c34e..ded2d3f 100644 --- a/src/lib/EncryptButton.svelte +++ b/src/lib/EncryptButton.svelte @@ -42,7 +42,9 @@ } convertToBase64(file).then((base64) => { encrypt(base64).then((encrypted_content => { - let encrypted_file: Blob = new Blob(encrypted_content, {type: "text/plain"}); + console.log(encrypted_content) + let encrypted_b64: string = btoa(unescape(encodeURIComponent(encrypted_content))); + let encrypted_file: Blob = new Blob([encrypted_b64], {type: "text/plain"}); let url = URL.createObjectURL(encrypted_file); let a = document.createElement("a"); a.href = url; diff --git a/src/lib/cryptlib.ts b/src/lib/cryptlib.ts index afc49b6..a6920e1 100644 --- a/src/lib/cryptlib.ts +++ b/src/lib/cryptlib.ts @@ -71,8 +71,8 @@ export async function encrypt(string: string) { key, encoded ); - console.log(ciphertext) - return ciphertext + let decodedCiphertext = dec.decode(ciphertext); + return decodedCiphertext } diff --git a/src/lib/generalStore.ts b/src/lib/generalStore.ts new file mode 100644 index 0000000..5a27cb0 --- /dev/null +++ b/src/lib/generalStore.ts @@ -0,0 +1,3 @@ +import { writable} from 'svelte/store'; + +export let filename = writable("Encrypted.b64"); \ No newline at end of file diff --git a/src/lib/pwgen.ts b/src/lib/pwgen.ts index 65d8b6d..a37bad8 100644 --- a/src/lib/pwgen.ts +++ b/src/lib/pwgen.ts @@ -10,5 +10,5 @@ function generateRandomString(length: number): string { } const password: string = generateRandomString(16); -export const globalPassword = writable(password); +export let globalPassword = writable(password);