summaryrefslogtreecommitdiffstats
path: root/crxid
blob: 7c0236c464866e8acdd811bff58fe14fb6af2b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /bin/sh
# Get CRX id from RSA key
# usage: crxid PEM_FILE

set -efu

pem_path=$1

digest=$(
  openssl rsa  -in "$pem_path" -pubout -outform der 2>/dev/null |
  openssl dgst -sha256 -hex |
  sed 's/^(stdin)= //;s/.*/\U&/'
)

script="
  obase=16;
  ibase=16;
  ascii_a=61;
  $(echo $digest | cut -b-32 | sed 's/./ascii_a + &;/g')
"

echo "$script" | bc | xxd -r -p
echo