From 991590bb58964c07cd58b5c385c91c2c3390cb00 Mon Sep 17 00:00:00 2001 From: cp2n19 <cp2n19@soton.ac.uk> Date: Mon, 25 Apr 2022 15:50:43 +0100 Subject: [PATCH] Added option to change user-input encryption key, instructions to use it --- src/css/button.css | 14 ++++++++++++++ src/html/popup.html | 2 +- src/js/background.js | 1 - src/js/popup.js | 26 +++++++++++++++++++++----- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/css/button.css b/src/css/button.css index c4337a7..08ac955 100644 --- a/src/css/button.css +++ b/src/css/button.css @@ -10,4 +10,18 @@ height: 50px; width: 100px; margin: 10px; +} + +#instTab{ + border: 5px solid powderblue; + height: 50px; + width: 100px; + margin: 10px; +} + +#changeKey{ + border: 5px solid powderblue; + height: 50px; + width: 100px; + margin: 10px; } \ No newline at end of file diff --git a/src/html/popup.html b/src/html/popup.html index 748136f..d932173 100644 --- a/src/html/popup.html +++ b/src/html/popup.html @@ -13,7 +13,7 @@ </div> <div class="grid-item"> <a href="instructions.html" target="_blank"> - <button> + <button id="instTab"> Instructions </button> </a> diff --git a/src/js/background.js b/src/js/background.js index 401a4d1..b35c53e 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -1,4 +1,3 @@ -let color = '#3aa757'; var cryptojs = require("crypto-js") chrome.runtime.onInstalled.addListener(function() { diff --git a/src/js/popup.js b/src/js/popup.js index e9b0aea..86c4922 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1,4 +1,4 @@ -var crypto = require('crypto-js'); +var cryptojs = require('crypto-js'); var filesaver = require('file-saver'); let encrypt = document.getElementById("encrypt"); let decrypt = document.getElementById("decrypt"); @@ -43,10 +43,10 @@ input_enc.addEventListener("change", () => { var iv = result.iv; // Convert: ArrayBuffer -> WordArray - var wordArray = crypto.lib.WordArray.create(reader.result); + var wordArray = cryptojs.lib.WordArray.create(reader.result); // Encryption: I: WordArray -> O: -> Base64 encoded string (OpenSSL-format) - var encrypted = crypto.AES.encrypt(wordArray, key,{iv: iv}).toString(); + var encrypted = cryptojs.AES.encrypt(wordArray, key,{iv: iv}).toString(); // Create blob from string var fileEnc = new Blob([encrypted]); @@ -88,7 +88,7 @@ input_dec.addEventListener("change", () => { var iv = result.iv; // Decryption: I: Base64 encoded string (OpenSSL-format) -> O: WordArray - var decrypted = crypto.AES.decrypt(reader.result, key,{iv: iv}); + var decrypted = cryptojs.AES.decrypt(reader.result, key,{iv: iv}); // Convert: WordArray -> typed array var typedArray = convertWordArrayToUint8Array(decrypted); @@ -135,5 +135,21 @@ function getUserKey(){ let userKey = window.prompt("Input new encryption key"); if (userKey == null) return; - alert(userKey); + + var vector = cryptojs.lib.WordArray.random(16); + var salt = cryptojs.lib.WordArray.random(128/8); + var newKey = cryptojs.PBKDF2(userKey, salt, { keySize: 256 / 32, iterations: 1000 }); + alert("3"); + + chrome.storage.local.set({iv: vector}, function(){ + alert("New Vector Set"); + }); + + chrome.storage.local.set({key: newKey}, function (){ + alert("New Key Set"); + }); + + chrome.storage.local.get(['key'],function(result) { + alert('Value currently is ' + result.key); + }) } \ No newline at end of file -- GitLab