Skip to main content
Version: 3.27.2

digest()

The digest() method of the SubtleCrypto interface generates a digest of the given data. A digest is a short fixed-length value derived from some variable-length input. Cryptographic digests should exhibit collision-resistance, meaning that it's hard to come up with two different inputs that have the same digest value.

It takes as its arguments an identifier for the digest algorithm to use and the data to digest. It returns a Promise which will be fulfilled with the digest.

Syntax

digest(algorithm, data)

Parameters

  • algorithm
    • : This may be a string or an object with a single property name that is a string. The string names the hash function to use. Supported values are:
      • "MD5" (but don't use this in cryptographic applications)
      • "SHA-1" (but don't use this in cryptographic applications)
      • "SHA-256"
      • "SHA-384"
      • "SHA-512".
  • data
    • : An ArrayBuffer, a TypedArray or a DataView object containing the data to be digested.

Return value

A Promise that fulfills with an ArrayBuffer containing the digest.

Supported algorithms

Digest algorithms, also known as cryptographic hash functions, transform an arbitrarily large block of data into a fixed-size output, usually much shorter than the input. They have a variety of applications in cryptography.