function public static function Crypt::parseSriIntegrity

8.x-3.x Crypt.php public static Crypt::parseSriIntegrity($integrity)

Parses a SRI integrity value to separate the algorithm from the hash.


string $integrity: An integrity value beginning with a prefix indicating a particular hash algorithm (currently the allowed prefixes are sha256, sha384, and sha512), followed by a dash, and ending with the actual base64 encoded hash.

Return value

array An indexed array containing intended for use with list():

  • algorithm - (string) The provided or matched algorithm.
  • hash - (string) The base64 encoded hash.


Extends \Drupal\Component\Utility\Crypt.



Source src/Utility/Crypt.php (line 153)

public static function parseSriIntegrity($integrity) {
  // Extract the algorithm and base64 encoded hash.
  preg_match(Crypt::SRI_INTEGRITY_REGEXP, $integrity, $matches);
  $algorithm = !empty($matches[1]) ? $matches[1] : FALSE;
  $hash = !empty($matches[2]) ? $matches[2] : $integrity;

  // Attempt to determine the algorithm used if one wasn't prepended.
  if (!$algorithm) {
    $algorithm = static::determineHashBase64Algorithm($hash);

  return [$algorithm, $hash];