11.2.1 Compute Method

Computes the hash of a sequence of bytes, using the currently selected algorithm.

Input Arguments

Name

Type

Mandatory

Description

Input

XPRIM_Binary

Yes

The binary data you want to calculate the hash for

 

Output Arguments

Name

Type

Mandatory

Description

Result

XPRIM_Binary

Yes

The hash (bytes)

 

Return Value

None

Examples

Hash a password using PBKDF2 algorithm (5000 iteration)

Define_Com Class(#PRIM_DC.UnicodeString) Name(#PasswordString)

Define_Com Class(#XPRIM_Binary) Name(#PasswordBytes)

Define_Com Class(#XPRIM_Binary) Name(#HashBytes)

Define_Com Class(#XPRIM_Crypto_Hash) Name(#HashGenerator)

. . .

* Assume #PasswordString contains the password to hash

* Convert password string (#PasswordString) into bytes

#PasswordBytes.FromStringUsingUTF8 String(#PasswordString)

* Set algorithm to PBKDF2, using 5000 iteration

#HashGenerator.UsePBKDF2 Iteration(5000)

* Calculate hash

#HashGenerator.Compute Input(#PasswordBytes) Result(#HashBytes)

* Get hash value as Base64 string, and put in #HASH field

#HASH := #HashBytes.AsBase64String