trilium/src/services/my_scrypt.js

28 lines
662 B
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
const optionService = require('./options');
const crypto = require('crypto');
async function getVerificationHash(password) {
2018-04-03 09:47:46 +08:00
const salt = await optionService.getOption('passwordVerificationSalt');
return getScryptHash(password, salt);
}
async function getPasswordDerivedKey(password) {
2018-04-03 09:47:46 +08:00
const salt = await optionService.getOption('passwordDerivedKeySalt');
return getScryptHash(password, salt);
}
async function getScryptHash(password, salt) {
const hashed = crypto.scryptSync(password, salt, 32,
{N: 16384, r:8, p:1});
return hashed;
}
module.exports = {
getVerificationHash,
getPasswordDerivedKey
};