cleaned up old CTR encryption methods

This commit is contained in:
azivner
2017-11-18 12:48:54 -05:00
parent 35d5289cca
commit 6b226a319c
3 changed files with 0 additions and 900 deletions

View File

@@ -1,8 +1,6 @@
const options = require('./options');
const my_scrypt = require('./my_scrypt');
const utils = require('./utils');
const crypto = require('crypto');
const aesjs = require('./aes');
const data_encryption = require('./data_encryption');
async function verifyPassword(password) {
@@ -13,31 +11,6 @@ async function verifyPassword(password) {
return givenPasswordHash === dbPasswordHash;
}
function decryptDataKey(passwordDerivedKey, encryptedBase64) {
const encryptedBytes = utils.fromBase64(encryptedBase64);
const aes = getAes(passwordDerivedKey);
return Array.from(aes.decrypt(encryptedBytes).slice(4));
}
function encryptDataKey(passwordDerivedKey, plainText) {
const aes = getAes(passwordDerivedKey);
const plainTextBuffer = Buffer.from(plainText, 'latin1');
const digest = crypto.createHash('sha256').update(plainTextBuffer).digest().slice(0, 4);
const encryptedBytes = aes.encrypt(Buffer.concat([digest, plainTextBuffer]));
return utils.toBase64(encryptedBytes);
}
async function setDataKey(passwordDerivedKey, plainText) {
const newEncryptedDataKey = encryptDataKey(passwordDerivedKey, plainText);
await options.setOption('encrypted_data_key', newEncryptedDataKey);
}
async function setDataKeyCbc(password, plainText) {
const passwordDerivedKey = await my_scrypt.getPasswordDerivedKey(password);
@@ -52,16 +25,6 @@ async function setDataKeyCbc(password, plainText) {
await options.setOption('encrypted_data_key', newEncryptedDataKey);
}
async function getDecryptedDataKey(password) {
const passwordDerivedKey = await my_scrypt.getPasswordDerivedKey(password);
const encryptedDataKey = await options.getOption('encrypted_data_key');
const decryptedDataKey = decryptDataKey(passwordDerivedKey, encryptedDataKey);
return decryptedDataKey;
}
async function getDecryptedDataKeyCbc(password) {
const passwordDerivedKey = await my_scrypt.getPasswordDerivedKey(password);
@@ -73,14 +36,8 @@ async function getDecryptedDataKeyCbc(password) {
return decryptedDataKey;
}
function getAes(key) {
return new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
}
module.exports = {
verifyPassword,
getDecryptedDataKey,
getDecryptedDataKeyCbc,
setDataKey,
setDataKeyCbc
};