UNPKG

@citrineos/data

Version:

The OCPP data module which includes all persistence layer implementation.

26 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Pbkdf2 = void 0; const crypto_1 = require("crypto"); class Pbkdf2 { constructor() { this.iterations = 1000; this.keyLen = 64; this.digest = 'sha512'; } getSaltedHash(password) { const salt = (0, crypto_1.randomBytes)(16).toString('hex'); const hash = this.getHashFromStringWithSalt(password, salt); return `PBKDF2:${this.iterations}:${this.keyLen}:${this.digest}:${salt}:${hash}`; } isHashMatch(storedValue, inputPassword) { const [_algorithm, _iterations, _keyLen, _digest, salt, originalHash] = storedValue.split(':'); const hash = this.getHashFromStringWithSalt(inputPassword, salt); return hash === originalHash; } getHashFromStringWithSalt(str, salt) { return (0, crypto_1.pbkdf2Sync)(str, salt, this.iterations, this.keyLen, this.digest).toString('hex'); } } exports.Pbkdf2 = Pbkdf2; //# sourceMappingURL=Pbkdf2.js.map