Sample code for 30+ languages & platforms
Lianja

Hash (Digest) a String

Hash the bytes of a string.

Chilkat Lianja Downloads

Lianja
loSb = createobject("CkStringBuilder")

loSb.Append("Hello World")

// Hashing algorithms (i.e. digest algorithms) operate on raw bytes.
// Therefore, we must specify the character encoding (utf-8, utf-16, iso-8859-1, etc.) to be used when hashing.

// Get the SHA256 hash in hex
lcSha256_hex = loSb.GetHash("sha256","hex","utf-8")
? "SHA256: " + lcSha256_hex

// Get the SHA384 hash in hex lowercase
lcSha384_hex = loSb.GetHash("sha384","hex_lower","utf-8")
? "SHA384: " + lcSha384_hex

// Get the SHA512 hash in base64
lcSha512_base64 = loSb.GetHash("sha512","base64","utf-8")
? "SHA512: " + lcSha512_base64

// Get the SHA1 hash in hex lowercase
lcSha1_hex = loSb.GetHash("sha1","hex_lower","utf-8")
? "SHA1: " + lcSha1_hex

// Get the CRC8 digest in decimal
lcCrc8_decimal = loSb.GetHash("crc8","decimal","utf-8")
? "CRC8: " + lcCrc8_decimal


release loSb