Atom

crypto.hash()

Computes a cryptographic digest.

Signature

crypto.hash(algorithm, data)

Parameters

Algorithm sha256 or sha512, and text or packed data.

Returns

32 or 64 packed bytes respectively.

Behavior

Reads but does not modify its input.

Errors

Unknown digest or backend failure.

Example

Atom
use crypto
use binary
assert(binary.hex(crypto.hash('sha256', 'abc')) == 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')

Hash a text value

Hashing computes a fixed-size digest. SHA-256 produces 32 bytes.

Atom
use crypto
print(count(crypto.hash('sha256', 'Atom')))
Output
32

The returned packed buffer contains the digest bytes.

Hash packed bytes

Hash an existing buffer without first decoding it as text.

Atom
use binary
use crypto
bytes = binary.utf8('Atom')
print(count(crypto.hash('sha256', bytes)))
Output
32

The algorithm hashes the supplied bytes and produces the same digest length.