How to generate SHA for integrity html tag?

Viewed 1816

I'm using this command to generate SHA hash in command line on my Mac:

openssl dgst -sha384 -binary FILENAME.js | openssl base64 -A

The result looks like this:

93Zn4wbvkSu+.......PksSwU4A+2a.....t0OOmyCompName:public

I then paste this sha with prefix in integrity html attribute: Like this:

<script type="text/javascript" integrity="sha384-93Zn4wbvkSu+.......PksSwU4A+2a.....t0OOmyCompName:public">

And Chrome gives me an error:

Error parsing 'integrity' attribute ('sha384-93Zn4wbvkSu+.......PksSwU4A+2a.....t0OOmyCompName:public'). The digest must be a valid, base64-encoded value.

I tried with myCompName:public and without. Help me please - how to correctly generate this integrity hash?

I don't use https://www.srihash.org/ because no cors enabled. Nginx serves my static files.

1 Answers

I found an error. Do not include in your integrity token this text in the end:

myCompName:public

If you delete -A key from you command in the end it will give you the same result but without name of your local machine and :public word ending.

so the right hash will look like this:

sha384-93Zn4wbvkSu+.......PksSwU4A+2a.....t0OO
Related