added decrypt, and file name handling

main
Johannes Bülow 2023-01-04 15:29:46 +01:00
parent 3bac4bbe9a
commit 917797c9be
3 changed files with 5 additions and 8 deletions

View File

@ -46,7 +46,7 @@
readFileContent(file).then((fileContent) => {
decrypt(atob(fileContent)).then(decryptedContent => {
console.log("Decrypted Base64: ", decryptedContent)
console.log(decodeURIComponent(escape(atob((decryptedContent)))));
console.log(decodeURIComponent(decryptedContent));
const decodedData = decodeURIComponent(escape(atob((decryptedContent))));
const outputArray = new Uint8Array(decodedData.length)
for (let i = 0; i < decodedData.length; i++) {

View File

@ -1,7 +1,7 @@
<script lang="ts">
import { onMount } from 'svelte';
import { encrypt } from './cryptlib';
let filename: string = "";
let filename: string;
function convertToBase64(blob: File): Promise<string> {
return new Promise((resolve, reject) => {
@ -34,13 +34,10 @@
}
filename = file.name;
console.log("Uploaded ", filename)
//Encoding file using Base64
convertToBase64(file).then((base64) => {
//encrypting the base64 encoded File
encrypt(base64).then((encrypted_content => {
console.log(encrypted_content)
let encrypted_b64: string = btoa(unescape(encodeURIComponent(encrypted_content)));
console.log("Encrypted Base64: ", encrypted_b64)
let encrypted_file: Blob = new Blob([encrypted_b64], {type: "text/plain"});
let url = URL.createObjectURL(encrypted_file);
let a = document.createElement("a");

View File

@ -84,7 +84,7 @@ update the "decryptedValue" box with the decrypted value.
If there was an error decrypting,
update the "decryptedValue" box with an error message.
*/
export async function decrypt(string: string) {
export async function decrypt(encryptedContent) {
let keyMaterial = await getKeyMaterial();
let key = await getKey(keyMaterial, salt);
@ -95,7 +95,7 @@ export async function decrypt(string: string) {
iv: iv
},
key,
ciphertext
encryptedContent
);
let dec = new TextDecoder();