Sha256 Hashes in AngelScript

Here’s the translation of the SHA256 Hashes example to AngelScript, formatted in Markdown suitable for Hugo:

SHA256 hashes are frequently used to compute short identities for binary or text blobs. For example, TLS/SSL certificates use SHA256 to compute a certificate’s signature. Here’s how to compute SHA256 hashes in AngelScript.

#include "crypto.as"
#include "string.as"

void main()
{
    string s = "sha256 this string";

    // Here we start with a new hash.
    SHA256 hash;

    // We can write the string directly to the hash object
    hash.calculate(s);

    // This gets the finalized hash result as a string
    string result = hash.getHash();

    print(s + "\n");
    print(result + "\n");
}

AngelScript doesn’t have built-in crypto functions, so we assume there’s a crypto.as module that provides the SHA256 class. The usage is simplified compared to the original example, as AngelScript’s string handling is more straightforward.

Running the program computes the hash and prints it in a hexadecimal format.

$ angelscript sha256-hashes.as
sha256 this string
1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a...

You can compute other hashes using a similar pattern to the one shown above. For example, to compute SHA512 hashes, you would use a hypothetical SHA512 class instead.

Note that if you need cryptographically secure hashes, you should carefully research hash strength!

The exact implementation details may vary depending on the specific crypto library used with AngelScript. Always refer to the documentation of your chosen crypto library for the most accurate information.