added "DB dump" tool, WIP

This commit is contained in:
zadam
2022-02-10 23:37:25 +01:00
parent df91192b97
commit 6c9fc364a3
7 changed files with 1446 additions and 0 deletions

33
dump-db/inc/data_key.js Normal file
View File

@@ -0,0 +1,33 @@
import crypto from "crypto";
import sql from "./sql.js";
function getDataKey(password) {
const passwordDerivedKey = getPasswordDerivedKey(password);
const encryptedDataKey = getOption('encryptedDataKey');
const decryptedDataKey = decrypt(passwordDerivedKey, encryptedDataKey, 16);
return decryptedDataKey;
}
function getPasswordDerivedKey(password) {
const salt = getOption('passwordDerivedKeySalt');
return getScryptHash(password, salt);
}
function getScryptHash(password, salt) {
const hashed = crypto.scryptSync(password, salt, 32,
{N: 16384, r:8, p:1});
return hashed;
}
function getOption(name) {
return sql.getValue("SELECT value FROM options WHERE name = ?", name);
}
module.exports = {
getDataKey
};