3.4.3

Getting started

ACCOUNTS

Data pipelines

Administration

Advanced

Powered By GitBook

hash

The hash statement is used to generate a base-16 or base-64 encoded hash of data stored in a variable or named buffer.

Syntax

hash sha256 [HMAC [b16|b64]key] target|{target}asresult[b16|b64]

hash md5target|{target}asresult[b16|b64]

Details

The hash statement uses the contents of target as its input and places the final result into result. The SHA256 and MD5 hash algorithms are supported.

If target is surrounded with curly braces like {this} then it is taken to be the name of a memory buffer and the contents of the buffer will be used as input. Otherwise, it is treated as the name of the variable, the value of which will be hashed.

By default the resulting hash is base-16 encoded and the result placed into the variable specified by the result argument.

result is the name of the variable to put the output into, and not a reference to the contents of that variable. This is why it is not ${result}

If the optional HMACkey arguments are provided when the hash type is sha256 then the secret in key will be used to generate an HMAC-SHA-256 result. The optional b64 or b16 argument following the HMAC option indicates that key is base-64 or base-16 encoded. By default, a clear-text key is assumed.

If the optional b64 argument is used (base64 may also be specified) after the result variable, then the result will be base-64 encoded.

The optional b16 argument (base16 may also be used) after the result variable is provided for completeness, but need not be specified as this is the default encoding to use.

Example

Running the script:

1

var hash_me = "This is the data to hash"

2

var my_secret = "This is my secret key"

3

â€‹

4

# SHA256

5

hash sha256 hash_me as result

6

print The SHA256 hash of '${hash_me}' in base-16 is:

7

print ${result}${NEWLINE}

8

â€‹

9

hash sha256 hash_me as result b64

10

print The SHA256 hash of '${hash_me}' in base-64 is:

11

print ${result}${NEWLINE}

12

â€‹

13

# HMACSHA256

14

hash sha256 hmac ${my_secret} hash_me as result

15

print The HMACSHA256 hash of '${hash_me}' (using '${my_secret}') in base-16 is:

16

print ${result}${NEWLINE}

17

â€‹

18

hash sha256 hmac ${my_secret} hash_me as result b64

19

print The HMACSHA256 hash of '${hash_me}' (using '${my_secret}') in base-64 is:

20

print ${result}${NEWLINE}

Copied!

results in the following output:

1

The SHA256 hash of 'This is the data to hash' in base-16 is:

2

1702c37675c14d0ea99b7c23ec29c36286d1769a9f65212218d4380534a53a7a

3

â€‹

4

The SHA256 hash of 'This is the data to hash' in base-64 is:

5

FwLDdnXBTQ6pm3wj7CnDYobRdpqfZSEiGNQ4BTSlOno=

6

â€‹

7

The HMACSHA256 hash of 'This is the data to hash' (using 'This is my secret key') in base-16 is:

8

cf854e99094ea5c2a88ee0901a305d5f25dfb5a0f0905eec703618080567b4b5

9

â€‹

10

The HMACSHA256 hash of 'This is the data to hash' (using 'This is my secret key') in base-64 is:

11

z4VOmQlOpcKojuCQGjBdXyXftaDwkF7scDYYCAVntLU=

Copied!

Last modified 2yr ago