An open API service indexing awesome lists of open source software.

https://github.com/ping/srihash

bash function/script to generate an SRI hash for a remote resource
https://github.com/ping/srihash

Last synced: 2 months ago
JSON representation

bash function/script to generate an SRI hash for a remote resource

Awesome Lists containing this project

README

        

# srihash
bash function/script to generate an SRI hash for a remote resource

## Install
Not much of an install. Use either the bash function or script version.

Requires ``openssl``.

### 1. bash function
Add the ``srihash`` function to ``~/.bash_profile``

```bash
curl -sL 'https://raw.githubusercontent.com/ping/srihash/master/srihash' >> ~/.bash_profile \
&& source ~/.bash_profile
```

### 2. bash script
Download ``srihash.sh`` locally.

```bash
curl -s -o 'srihash.sh' 'https://raw.githubusercontent.com/ping/srihash/master/srihash.sh' \
&& chmod +x srihash.sh
```

## Usage

```bash
srihash 'https://url/to/a.css' 'https://url/to/another.js'
# or
./srihash.sh 'https://url/to/a.css' 'https://url/to/another.js'

# Use sha256 instead
srihash 'sha256' 'https://url/to/a.css' 'https://url/to/another.js'
# or
./srihash.sh 'sha256' 'https://url/to/a.css' 'https://url/to/another.js'

# Use sha512 instead
srihash 'sha512' 'https://url/to/a.css' 'https://url/to/another.js'
# or
./srihash.sh 'sha512' 'https://url/to/a.css' 'https://url/to/another.js'
```

Example:

```bash
srihash 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css' \
'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js'
```
```
==== Generating hash for: https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css ====
sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u

==== Generating hash for: https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js ====
sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa

```

The generated ````/``<link>`` markup will automatically be copied to the clipboard.