added decrypt, and file name handling
parent
3bac4bbe9a
commit
917797c9be
|
@ -46,7 +46,7 @@
|
||||||
readFileContent(file).then((fileContent) => {
|
readFileContent(file).then((fileContent) => {
|
||||||
decrypt(atob(fileContent)).then(decryptedContent => {
|
decrypt(atob(fileContent)).then(decryptedContent => {
|
||||||
console.log("Decrypted Base64: ", decryptedContent)
|
console.log("Decrypted Base64: ", decryptedContent)
|
||||||
console.log(decodeURIComponent(escape(atob((decryptedContent)))));
|
console.log(decodeURIComponent(decryptedContent));
|
||||||
const decodedData = decodeURIComponent(escape(atob((decryptedContent))));
|
const decodedData = decodeURIComponent(escape(atob((decryptedContent))));
|
||||||
const outputArray = new Uint8Array(decodedData.length)
|
const outputArray = new Uint8Array(decodedData.length)
|
||||||
for (let i = 0; i < decodedData.length; i++) {
|
for (let i = 0; i < decodedData.length; i++) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { encrypt } from './cryptlib';
|
import { encrypt } from './cryptlib';
|
||||||
let filename: string = "";
|
let filename: string;
|
||||||
|
|
||||||
function convertToBase64(blob: File): Promise<string> {
|
function convertToBase64(blob: File): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -34,13 +34,10 @@
|
||||||
}
|
}
|
||||||
filename = file.name;
|
filename = file.name;
|
||||||
console.log("Uploaded ", filename)
|
console.log("Uploaded ", filename)
|
||||||
//Encoding file using Base64
|
|
||||||
convertToBase64(file).then((base64) => {
|
convertToBase64(file).then((base64) => {
|
||||||
//encrypting the base64 encoded File
|
|
||||||
encrypt(base64).then((encrypted_content => {
|
encrypt(base64).then((encrypted_content => {
|
||||||
|
console.log(encrypted_content)
|
||||||
let encrypted_b64: string = btoa(unescape(encodeURIComponent(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 encrypted_file: Blob = new Blob([encrypted_b64], {type: "text/plain"});
|
||||||
let url = URL.createObjectURL(encrypted_file);
|
let url = URL.createObjectURL(encrypted_file);
|
||||||
let a = document.createElement("a");
|
let a = document.createElement("a");
|
||||||
|
|
|
@ -84,7 +84,7 @@ update the "decryptedValue" box with the decrypted value.
|
||||||
If there was an error decrypting,
|
If there was an error decrypting,
|
||||||
update the "decryptedValue" box with an error message.
|
update the "decryptedValue" box with an error message.
|
||||||
*/
|
*/
|
||||||
export async function decrypt(string: string) {
|
export async function decrypt(encryptedContent) {
|
||||||
let keyMaterial = await getKeyMaterial();
|
let keyMaterial = await getKeyMaterial();
|
||||||
let key = await getKey(keyMaterial, salt);
|
let key = await getKey(keyMaterial, salt);
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ export async function decrypt(string: string) {
|
||||||
iv: iv
|
iv: iv
|
||||||
},
|
},
|
||||||
key,
|
key,
|
||||||
ciphertext
|
encryptedContent
|
||||||
);
|
);
|
||||||
|
|
||||||
let dec = new TextDecoder();
|
let dec = new TextDecoder();
|
||||||
|
|
Loading…
Reference in New Issue