crypto_digest.md 4.0 KB


id: crypto.digest title: Crypto.Digest

sidebar_label: Introduction

A core tool of modern cryptography, message digests are a string of digits created by one-way hash function that is practically infeasible to reverse.

Because they are generally fast to compute, they are often used to protect the integrity of files and other data.

Crypto.Digest supports a wide range of commonly used digests and redundancy checking formulas.

For more general information, see https://en.wikipedia.org/wiki/Cryptographic_hash_function

Supported Digests

The following is a list of available digests :

Name Size of Message Digest (bytes)
Crypto.WhirlpoolDigest 64
Crypto.SHA3Digest (TSHA3_512) 64
Crypto.SHA512Digest 64
Crypto.Blake2BDigest (TBlake2B_512) 64
Crypto.SHA3Digest (TSHA3_384) 48
Crypto.Blake2BDigest (TBlake2B_384) 48
Crypto.Ripemd320Digest 40
Crypto.SHA3Digest (TSHA3_256) 32
Crypto.SHA256Digest 32
Crypto.Ripemd256Digest 32
Crypto.Blake2BDigest (TBlake2B_256) 32
Crypto.SHA3Digest (TSHA3_224) 28
Crypto.TigerDigest 24
Crypto.SHA1Digest 20
Crypto.Ripemd160Digest 20
Crypto.Blake2BDigest (TBlake2B_160) 20
Crypto.Ripemd128Digest 16
Crypto.MD5Digest 16

Types

Type Description
TMessageDigest An abstract base type for message digest implementations.
TDigestRegister A register of available message digests and cryptographic functions.

Functions

Function GetMessageDigest:TMessageDigest(name:String)

Gets a digest of the specified name.

A TNoSuchAlgorithmException is thrown if the requested digest is not available.

Example

SuperStrict

Framework brl.standardio
Import Crypto.MD5Digest

Local data:String = "Hello World"

Local digest:TMessageDigest = GetMessageDigest("md5")

If digest Then
	Print digest.Digest(data)
End If


Function ListDigests:TList()

Returns a list of all currently registered digests.

The returned digest names can be used with GetMessageDigest to get a TMessageDigest instance.

Example

SuperStrict

Framework brl.standardio
Import Crypto.MD5Digest
Import Crypto.SHA3Digest

Print "Available digests:"
For Local digest:String = EachIn ListDigests()
	Print "  " + digest
Next


Function BytesToHex:String(bytes:Byte[], uppercase:Int = False)

Returns a hex representation of Byte array bytes.


Function BytesToHex:String(bytes:Byte Ptr, size:Int, uppercase:Int = False)

Returns a hex representation of size bytes.