Skip to content

Instantly share code, notes, and snippets.

@webuniverseio
Forked from WebReflection/csp
Created June 8, 2017 13:44
Show Gist options
  • Save webuniverseio/3ca97204d74c0c03afb86e9ecfebc7ec to your computer and use it in GitHub Desktop.
Save webuniverseio/3ca97204d74c0c03afb86e9ecfebc7ec to your computer and use it in GitHub Desktop.
Generates the right sha1 and sha256 for Content Security Policy aware scripts
#!/usr/bin/env bash
echo ''
if [ "$1" = "" ]; then
echo 'csp sha1 and sha256 generatoor'
echo 'csp "code"'
echo 'csp /file-name'
else
if [ -f "$1" ]; then
CONTENT=$(cat $1)
else
CONTENT=$1
fi
echo "sha1-$(echo -n "$CONTENT" | openssl dgst -sha1 -binary | base64)"
echo "sha256-$(echo -n "$CONTENT" | openssl dgst -sha256 -binary | base64)"
fi
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment