hs.hash
ModuleModule for hashing and encoding operations
Properties
This module has no properties.
Methods
hs.hash.base64Encode(data) -> string
Encode a string to base64
Declaration
hs.hash.base64Encode(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The string to encode |
Returns
string
Base64 encoded string
Example
console.log(hs.hash.base64Encode("Hello"))
hs.hash.base64Decode(data) -> string
Decode a base64 string
Declaration
hs.hash.base64Decode(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The base64 string to decode |
Returns
string
Decoded string, or nil if the input is invalid
Example
console.log(hs.hash.base64Decode("SGVsbG8="))
hs.hash.md5(data) -> string
Generate MD5 hash of a string
Declaration
hs.hash.md5(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The string to hash |
Returns
string
Hexadecimal MD5 hash
Example
console.log(hs.hash.md5("hello"))
hs.hash.sha1(data) -> string
Generate SHA1 hash of a string
Declaration
hs.hash.sha1(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The string to hash |
Returns
string
Hexadecimal SHA1 hash
Example
console.log(hs.hash.sha1("hello"))
hs.hash.sha256(data) -> string
Generate SHA256 hash of a string
Declaration
hs.hash.sha256(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The string to hash |
Returns
string
Hexadecimal SHA256 hash
Example
console.log(hs.hash.sha256("hello"))
hs.hash.sha512(data) -> string
Generate SHA512 hash of a string
Declaration
hs.hash.sha512(data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The string to hash |
Returns
string
Hexadecimal SHA512 hash
Example
console.log(hs.hash.sha512("hello"))
hs.hash.hmacMD5(key, data) -> string
Generate HMAC-MD5 of a string with a key
Declaration
hs.hash.hmacMD5(key, data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The secret key |
| data | string | The data to authenticate |
Returns
string
Hexadecimal HMAC-MD5
Example
console.log(hs.hash.hmacMD5("secret", "hello"))
hs.hash.hmacSHA1(key, data) -> string
Generate HMAC-SHA1 of a string with a key
Declaration
hs.hash.hmacSHA1(key, data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The secret key |
| data | string | The data to authenticate |
Returns
string
Hexadecimal HMAC-SHA1
Example
console.log(hs.hash.hmacSHA1("secret", "hello"))
hs.hash.hmacSHA256(key, data) -> string
Generate HMAC-SHA256 of a string with a key
Declaration
hs.hash.hmacSHA256(key, data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The secret key |
| data | string | The data to authenticate |
Returns
string
Hexadecimal HMAC-SHA256
Example
console.log(hs.hash.hmacSHA256("secret", "hello"))
hs.hash.hmacSHA512(key, data) -> string
Generate HMAC-SHA512 of a string with a key
Declaration
hs.hash.hmacSHA512(key, data) -> string
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The secret key |
| data | string | The data to authenticate |
Returns
string
Hexadecimal HMAC-SHA512
Example
console.log(hs.hash.hmacSHA512("secret", "hello"))