@rtorcato/js-common / crypto
crypto
Functions
hashString()
hashString(
str,algorithm?):string
Defined in: crypto/index.ts:9
Hashes a string using the specified algorithm.
Parameters
str
string
The string to hash.
algorithm?
string = 'sha256'
The hash algorithm (default: 'sha256').
Returns
string
The hex-encoded hash.
randomHex()
randomHex(
length?):string
Defined in: crypto/index.ts:18
Generates a random hex string of the specified length (in bytes).
Parameters
length?
number = 16
The number of bytes (not hex chars).
Returns
string
A random hex string.
hmacHash()
hmacHash(
str,secret,algorithm?):string
Defined in: crypto/index.ts:29
Creates an HMAC hash of a string using a secret and algorithm.
Parameters
str
string
The string to hash.
secret
string
The secret key.
algorithm?
string = 'sha256'
The hash algorithm (default: 'sha256').
Returns
string
The hex-encoded HMAC.
base64Encode()
base64Encode(
str):string
Defined in: crypto/index.ts:38
Encodes a string to base64.
Parameters
str
string
The string to encode.
Returns
string
The base64-encoded string.
base64Decode()
base64Decode(
b64):string
Defined in: crypto/index.ts:47
Decodes a base64 string.
Parameters
b64
string
The base64 string to decode.
Returns
string
The decoded string.