UNPKG

@citrineos/data

Version:

The OCPP data module which includes all persistence layer implementation.

20 lines 834 B
import { pbkdf2Sync, randomBytes } from 'crypto'; export class Pbkdf2 { iterations = 1000; keyLen = 64; digest = 'sha512'; getSaltedHash(password) { const salt = 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 pbkdf2Sync(str, salt, this.iterations, this.keyLen, this.digest).toString('hex'); } } //# sourceMappingURL=Pbkdf2.js.map