Hash type
  • 28 Nov 2022
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Hash type

  • Dark
    Light

Article Summary

The hash type provides functions for generating hash codes with various hashing algorithms.

Usage

To use any of the functions described on this page, you must prefix them with the hash type name:

Hash.computeSha256("some value")

And if you already named something else "Hash", you need an additional prefix:

HiveTypes.Hash.computeSha256("some value")

computeSha256 function

Generates the SHA256 hash of the given text (first parameter). The second parameter defines in which format the generated hash will be returned.
Syntax: computeSha256(value, isBase64Encoded)

If it is true (which is the default value) the hash will be returned base64 encoded.
If it is false the hash will be returned hex (base16) encoded.

Hash.computeSha256("")                  // 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
Hash.computeSha256("some value")        // qz0H8xacy9DtbEtF3iFRn5+TjHLSQSSZiquUnOg7tRs=
Hash.computeSha256("", false)           // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Hash.computeSha256("some value", false) // ab3d07f3169ccbd0ed6c4b45de21519f9f938c72d24124998aab949ce83bb51b

computeHmacSha256 function

Generates the HMAC SHA256 hash of the given text (first parameter) with the given. The second parameter is the secret text which is used to generate the hash. The third parameter defines in which format the generated hash will be returned.
Syntax: computeHmacSha256(value, secret, isBase64Encoded)

If it is true (which is the default value) the hash will be returned base64 encoded.
If it is false the hash will be returned hex (base16) encoded.

Hash.computeHmacSha256("", "")                             // thNnmggU2ex3L5XXeMNfxf8Wl8STcVZTxscSFEKSxa0=
Hash.computeHmacSha256("some value", "some secret")        // gcOIOIoay4FP/bY7cDX/3xf8JheKkEwUWmL1cyVTdLg=
Hash.computeHmacSha256("", "some secret", false)           // f6ea2d6efc05da393de3fa47d17eda28ae5e25197501e889e4d995f8e53ea8f6
Hash.computeHmacSha256("some value", "some secret", false) // 81c388388a1acb814ffdb63b7035ffdf17fc26178a904c145a62f573255374b8



Was this article helpful?

What's Next