Skip to content

Instantly share code, notes, and snippets.

@qutorial
Created October 9, 2017 12:08
Show Gist options
  • Save qutorial/88689eb59d503f7b3c7a91ea3515fa0c to your computer and use it in GitHub Desktop.
Save qutorial/88689eb59d503f7b3c7a91ea3515fa0c to your computer and use it in GitHub Desktop.
Integrity for HTML links in Bash
# Add this function to your ~/.bashrc
# Calculates SHA384 integrity attribute given a URL
function integrity {
echo sha384-`curl -s $1 | openssl dgst -sha384 -binary | openssl base64 -A`
}
# Documentation
#
# Example:
# $ integrity https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css
# sha384-370KB8zqOlHxys9dcOyC7aCeXVtGyiKkWkp+cn8Mfoi13/sPj7fvSuhKRRdFbcip
#
# Can be used like this in your HTML:
# <link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" rel="stylesheet" crossorigin="anonymous"
# integrity="sha384-370KB8zqOlHxys9dcOyC7aCeXVtGyiKkWkp+cn8Mfoi13/sPj7fvSuhKRRdFbcip">
#
# See also: https://www.srihash.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment