Skip to content

Latest commit

 

History

History
79 lines (46 loc) · 2 KB

Security.md

File metadata and controls

79 lines (46 loc) · 2 KB

myhelpers / Security

Namespace: Security

Table of contents

Functions

Functions

generateBase64RandomKey

generateBase64RandomKey(length?): string

Generate random base64 key

Parameters

Name Type Default value Description
length number 32 Length of the key to be generated

Returns

string

Generated key in string format


hashData

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()

Parameters

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.)

Returns

string

Data prefixed with the keyed hash


validateData

validateData(data, key, algorithm?): string | boolean

Validates if the given data is tampered.

see hashData()

Parameters

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

Returns

string | boolean

the real data with the hash stripped off. False if the data is tampered.