Skip to content

Instantly share code, notes, and snippets.

Created February 1, 2016 14:58
Show Gist options
  • Save anonymous/e05e0ff71993d6a6d757 to your computer and use it in GitHub Desktop.
Save anonymous/e05e0ff71993d6a6d757 to your computer and use it in GitHub Desktop.
Build a sub-resource integrity string (js | css). Usage: subresource-integrity cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js
if [ ${1: -4} == ".css" ]; then h="<link href=\"//"$1"\""; f=" rel=\"stylesheet\">"; else h="<script src=\"//"$1"\""; f=" type=\"text/javascript\"></script>"; fi; echo $h" integrity=\"sha256-"`curl -s $1 | openssl dgst -sha256 -binary | openssl enc -base64 -A`" sha512-"`curl -s $1 | openssl dgst -sha512 -binary | openssl enc -base64 -A`"\" crossorigin=\"anonymous\""$f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment