Digest Object provides applications the functionality of a message digest algorithm, such as MD5, SHA-1 or SHA-256. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A Digest object starts out initialized. The data is processed through it using the update methods. At any point reset can be called to reset the digest.

Once all the data to be updated has been updated, one of the digest methods should be called to complete the hash computation.

The digest method can be called once for a given number of updates. After digest has been called, the Digest object is reset to its initialized state.

1 MD5

The MD5 message-digest algorithm is a widely used hash function producing a 128-bit hash value. Although MD5 was initially designed to be used as a cryptographic hash function, it has been found to suffer from extensive vulnerabilities. It can still be used as a checksum to verify data integrity, but only against unintentional corruption. It remains suitable for other non-cryptographic purposes, for example for determining the partition for a particular key in a partitioned database.

    var digest = new Ax.crypt.Digest("MD5");
    var hello1 = "Hello World 1";
    var hello2 = "Hello World 2";
    var digest1  = digest.update(hello1).digest();
    var digest2 = digest.update(hello2).digest();
    // CASE 1
    console.log("1:" + digest1);
    console.log("1:" + digest.update(hello1).digest());
    Ax.jsunit.assertEquals(digest1, digest.update(hello1).digest());
    // CASE 2
    console.log("2:" + digest2);
    console.log("2:" + digest.update(hello2).digest());
    Ax.jsunit.assertEquals(digest2, digest.update(hello2).digest());
    // CASE 3
    var digest3a = digest.update(hello1)

    var digest3b = digest.update(hello1)

    console.log("3:" + digest3a);
    console.log("3:" + digest3b);
    Ax.jsunit.assertEquals(digest3a, digest3b);
    // CASE 4
    var digest4 = digest.update(hello1)

    console.log("4:" + digest4);
    Ax.jsunit.assertEquals(digest2, digest4);
    // CASE 5
    console.log("5:" + digest.update(new Ax.net.URL("https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv")).digest());



The Secure Hash Algorithms are a family of cryptographic hash functions published by the National Institute of Standards and Technology (NIST) as a U.S. Federal Information Processing Standard (FIPS), including:

  • SHA-0: A retronym applied to the original version of the 160-bit hash function published in 1993 under the name "SHA". It was withdrawn shortly after publication due to an undisclosed "significant flaw" and replaced by the slightly revised version SHA-1.
  • SHA-1: A 160-bit hash function which resembles the earlier MD5 algorithm. This was designed by the National Security Agency (NSA) to be part of the Digital Signature Algorithm. Cryptographic weaknesses were discovered in SHA-1, and the standard was no longer approved for most cryptographic uses after 2010.
  • SHA-2: A family of two similar hash functions, with different block sizes, known as SHA-256 and SHA-512. They differ in the word size; SHA-256 uses 32-bit words where SHA-512 uses 64-bit words. There are also truncated versions of each standard, known as SHA-224, SHA-384, SHA-512/224 and SHA-512/256. These were also designed by the NSA.
  • SHA-3: A hash function formerly called Keccak, chosen in 2012 after a public competition among non-NSA designers. It supports the same hash lengths as SHA-2, and its internal structure differs significantly from the rest of the SHA family.
The corresponding standards are FIPS PUB 180 (original SHA), FIPS PUB 180-1 (SHA-1), FIPS PUB 180-2 (SHA-1, SHA-256, SHA-384, and SHA-512). NIST has updated Draft FIPS Publication 202, SHA-3 Standard separate from the Secure Hash Standard (SHS).

    var payload = "This is a text message";
    var digest1 = new Ax.crypt.Digest("SHA-1");

    var digest256 = new Ax.crypt.Digest("SHA-256");

    var digest512 = new Ax.crypt.Digest("SHA-512");

3 ResultSet digest

Digest will normally accept as input any object that can be converted to a byte[] such as a file, blob, string, etc. But it also accepts a ResultSet.

Hashing a ResultSet may be useful for junit tests so we can compute a hash on input data and assert this data reamins constant (unchanged) between succesive tests.

    var rs = Ax.db.executeQuery("SELECT * FROM systables ORDER by tabid");
    var digest1 = new Ax.crypt.Digest("MD5");

Notice that ResultSet may provide same columns and rows in same order to compute the same hash. So don't forget to use an specific order by.