Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22401899
secure-hasher.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
821 B
Referenced Files
None
Subscribers
None
secure-hasher.js
View Options
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
Details
Attached
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)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline