Hash, HMAC
Encode data using hash and HMAC methods:
1
start:
2
say Crypto("Hello World 😆").create_hash("sha256").digest("hex")
3
say Crypto("Hello World 😆").create_hmac("md5", "SECRET_KEY").digest("base64")
Copied!

Methods

Crypto(data)

The data parameter is the data to encrypt or encode, and it must be a string.

create_hash(algorithm)

The algorithm must be one of the following values:
1
MD5
2
SHA1
3
SHA224
4
SHA256
5
SHA384
6
SHA512
7
SHA3_224
8
SHA3_256
9
SHA3_384
10
SHA3_512
11
SHAKE_128
12
SHAKE_256
13
RIPEMD160
14
SM3
Copied!

create_hmac(algorithm, key)

Unlike the create_hash method, create_hmac requires a key to function. The list of accepted algorithms is the same.

digest(encoding)

The encoding must be either "base64" or "hex".

Error handling

When any operation fails, Null is returned and a say Error(error_message) is emitted.
Last modified 6mo ago