From de7bd68872ec727bc3ff9c47108e7c146dfa5ce8 Mon Sep 17 00:00:00 2001 From: Kgothatso Date: Sun, 24 Nov 2019 23:03:27 +0200 Subject: [PATCH] Adding the cryptography stuff This is probably the wrong way to use the cryptography. --- lib/core/cryptoUtil.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/core/cryptoUtil.js b/lib/core/cryptoUtil.js index 9066124..5859b47 100644 --- a/lib/core/cryptoUtil.js +++ b/lib/core/cryptoUtil.js @@ -1,26 +1,28 @@ const crypto = require('crypto'); -const algorithm = 'aes-256-ctr'; +const algorithm = 'aes-256-ecb'; const bip32 = require('bip32'); +// NOTE I'm not a cryptographer... so don't be reusing any code from below as I don't have no idea what I'm doing + +const iv = null; // If I knew what I was doing I would have a value assigned here... + module.exports.encrypt = (plainText, password) => { - // TODO encrypt text - // const cipher = crypto.createCipheriv(algorithm, password); + const key = crypto.createHash('sha256').update(password, 'utf8').digest(); + const cipher = crypto.createCipheriv(algorithm, key, iv); - // var cipherText = cipher.update(plainText, 'utf8', 'hex'); - // cipher += cipher.final('hex'); - - // console.log("CipherText: ", cipherText); - return plainText; + var cipherText = cipher.update(plainText, 'utf8', 'hex'); + cipherText += cipher.final('hex'); + return cipherText; } module.exports.decrypt = (cipherText, password) => { - // TODO decrypt cipherText - // const decipher = crypto.createDecipheriv(algorithm, password) + const key = crypto.createHash('sha256').update(password, 'utf8').digest(); + const decipher = crypto.createDecipheriv(algorithm, key, iv); - // var plainText = decipher.update(cipherText, 'hex', 'utf8'); - // plainText += decipher.final('utf8'); + var plainText = decipher.update(cipherText, 'hex', 'utf8'); + plainText += decipher.final('utf8'); - return cipherText; + return plainText; } module.exports.randomDerivationPath = function(hardenedDerivation) {