From 8ffbfb8123e88f2c5ffc29495da1e2aa25f94f12 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 23 May 2021 22:11:25 +0100 Subject: [PATCH] Started on some very basic crypto --- src/utils/CloudBackup.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/utils/CloudBackup.js diff --git a/src/utils/CloudBackup.js b/src/utils/CloudBackup.js new file mode 100644 index 00000000..41067407 --- /dev/null +++ b/src/utils/CloudBackup.js @@ -0,0 +1,32 @@ +/* eslint-disable */ +import sha256 from 'crypto-js/sha256'; +import aes from 'crypto-js/aes'; +import Base64 from 'crypto-js/enc-base64'; +import Hex from 'crypto-js/enc-hex'; +import Utf8 from 'crypto-js/enc-utf8'; + +/* Stringify, encrypt and encode data for transmission */ +const encryptData = (data, password) => { + const stringifiedData = JSON.stringify(data); + const encryptedData = aes.encrypt(stringifiedData, password); + return encryptedData.toString(); +}; + +/* Decrypt, decode and parse received data */ +const decryptData = (data, password) => { + return aes.decrypt(data, password).toString(Utf8); +}; + +/* Returns a splice of the hash of the users password */ +const makeSubHash = (pass) => sha256(pass).toString().slice(0, 14); + +/* Makes the backup */ +export const backup = (data, password) => { + // const subHash = makeSubHash(password); + const encryptedData = encryptData(data, password); + console.log(encryptedData); + console.log(decryptData(encryptedData, password)); +}; + +/* Restores the backup */ +export const restore = (backupId, password) => { };