Home Contents | # cipher.hash | Cipher/Hash | Core4 Lua Commands

## SYNOPSIS

hash = cipher.hash([alg])

## DESCRIPTION

The Core4 system includes a copy of mbed TLS.

This function creates a new object for calculating one-way hashes (message digests).

The optional parameter alg names the desired message digest algorithm.

When the parameter alg is not given, the object is created uninitialized. Before it can be used, the initialization function hash:init() must be called.

Supported algorithms are: MD2, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD160.

After initialization, data is fed to the algorithme by calling hash:update().

The result can be retrieved by calling hash:finish().

## RETURN VALUE

On success, returns a hash calculation instance.

If initialization failed, returns nil, a string describing the error and the mbedtls error code number.

## EXAMPLE

Calculate a SHA256 checksum

> > >
hash = cipher.hash("SHA256") hash:update("abc") print(hash:finish():hexdump())
00000000: BA 78 16 BF 8F 01 CF EA 41 41 40 DE 5D AE 22 23 .x......AA@.]."# 00000010: B0 03 61 A3 96 17 7A 9C B4 10 FF 61 F2 00 15 AD ..a...z....a....

## SEE ALSO

hash:init(), hash:update(), hash:finish()