Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995413
secure-hasher.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
906 B
Referenced Files
None
Subscribers
None
secure-hasher.ts
View Options
import
crypto
from
"crypto"
;
const
algorithm
=
"sha512"
;
import
{
promisify
}
from
"util"
;
const
pbkdf2
=
promisify
(
crypto
.
pbkdf2
);
const
SecureHasher
=
{
generateRandomSalt
(
salt_length
:
number
)
{
return
crypto
.
randomBytes
(
salt_length
).
toString
(
"base64"
);
},
async
hash
(
value_to_hash
:
crypto
.
BinaryLike
,
salt
:
crypto
.
BinaryLike
,
{
iterations
,
key_length
}
:
any
)
{
const
key
=
await
pbkdf2
(
value_to_hash
,
salt
,
iterations
,
key_length
,
algorithm
);
return
`
${
iterations
}
.
${
key_length
}
.
${
salt
}
.
${
key
.
toString
(
"hex"
)
}
`
;
},
async
matches
(
value
:
crypto
.
BinaryLike
,
hash_with_params
:
string
)
{
const
[
iterations
,
key_length
,
salt
,
hash
]
=
hash_with_params
.
split
(
"."
);
const
key
=
await
pbkdf2
(
value
,
salt
,
parseInt
(
iterations
,
10
),
parseInt
(
key_length
,
10
),
algorithm
);
return
key
.
toString
(
"hex"
)
===
hash
;
},
};
export
default
SecureHasher
;
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Dec 23, 03:52 (17 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556076
Default Alt Text
secure-hasher.ts (906 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment