Generate SHA256 for Integrity Origin

To Keep the Integrity of External Files:

script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"

to generate the integrity part you can use the following linux bash script followed by the src file:

#!/bin/bash url=$1 && file=“${url##*/}“ && wget $url && extension=“${url##*.}“ && echo -e „\n\n“ if [ $extension = ‚js‘ ] then echo -e „Generate JS HTML output\n“ echo -ne „<script type=\“text/javascript\“ src=\“$url\“ integrity=\“sha256-“ && echo -ne openssl dgst -sha256 -binary url | openssl base64 -A && echo -e „\“ crossorigin=\“anonymous\“></script>\n\n“ elif [ $extension = ‚css‘ ] then echo -e „Generate CSS HTML output\n“ echo -ne „\n\n“ else echo -ne „integrity=\“sha256-“ && echo -ne openssl dgst -sha256 -binary url | openssl base64 -A && echo -e „\“ crossorigin=\“anonymous\“\n\n“ fi

Schreibe einen Kommentar