myhelpers / Security
▸ generateBase64RandomKey(length?
): string
Generate random base64 key
Name | Type | Default value | Description |
---|---|---|---|
length |
number |
32 |
Length of the key to be generated |
string
Generated key in string format
▸ hashData(data
, key
, algorithm?
): string
Prefixes data with a keyed hash value so that it can later be detected if it is tampered.
see
validateData()
Name | Type | Default value | Description |
---|---|---|---|
data |
string |
undefined |
Data to be protected |
key |
string |
undefined |
Secret key to be used for generating hash |
algorithm |
string |
"sha256" |
Hashing algorithm (e.g. "md5", "sha1", "sha256", etc.) |
string
Data prefixed with the keyed hash
▸ validateData(data
, key
, algorithm?
): string
| boolean
Validates if the given data is tampered.
see
hashData()
Name | Type | Default value | Description |
---|---|---|---|
data |
string |
undefined |
Data to be validated. The data must be previously generated by [hashData()] . |
key |
string |
undefined |
Secret key that was previously used to generate the hash for the data in [hashData()] . function to see the supported hashing algorithms on your system. This must be the same as the value passed to [hashData()] when generating the hash for the data. |
algorithm |
string |
"sha256" |
Algorithm used to generate the data |
string
| boolean
the real data with the hash stripped off. False if the data is tampered.