SultanC
  1. Home
  2. Examples
  3. Cryptography

SHA-512 and HMAC-SHA-256, printed as hexadecimal

crypto/hashes.sn
// SHA-512 and HMAC-SHA-256, printed as hexadecimal.
import std.io.println;
import std.text.from_bytes;
import std.encoding.hex;
import std.crypto.sha512;
import std.crypto.digest;

def main(): int {
    let message: vector u8 = bytes_from_text("abc");
    let digest: vector u8 = sha512(&message);
    println(hex_encode(&digest));
    let key: vector u8 = bytes_from_text("key");
    let text: vector u8 = bytes_from_text("The quick brown fox jumps over the lazy dog");
    let tag: vector u8 = hmac_sha256(&key, &text);
    println(hex_encode(&tag));
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/crypto/hashes.sn

Or compile it to an executable:

./build/sultanc examples/en/crypto/hashes.sn -o build/example && ./build/example

Source on GitHub   All examples