Page MenuHomeSealhub

secure-hasher.js
No OneTemporary

Authored By
Unknown
Size
821 B
Referenced Files
None
Subscribers
None

secure-hasher.js

const crypto = require("crypto");
const algorithm = "sha512";
const { promisify } = require("util");
const pbkdf2 = promisify(crypto.pbkdf2);
const SecureHasher = {
generateRandomSalt(salt_length) {
return crypto.randomBytes(salt_length).toString("base64");
},
async hash(value_to_hash, salt, { iterations, key_length }) {
const key = await pbkdf2(
value_to_hash,
salt,
iterations,
key_length,
algorithm
);
return `${iterations}.${key_length}.${salt}.${key.toString("hex")}`;
},
matches(value, hash_with_params) {
const [iterations, key_length, salt, hash] = hash_with_params.split(
"."
);
return pbkdf2(
value,
salt,
parseInt(iterations, 10),
parseInt(key_length, 10),
algorithm
).then(key => key.toString("hex") === hash);
},
};
module.exports = SecureHasher;

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 18:26 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223573
Default Alt Text
secure-hasher.js (821 B)

Event Timeline