summaryrefslogtreecommitdiffstats
path: root/pubkey
blob: 4a6d781ca0c1dada631f5793e9289f2fe9b56c0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

KEY=$1
PASS=$2

declare -a ARGS
if [[ -n "$KEY" ]]; then
    if [[ ! -r "$KEY" ]]; then
        echo "Usage: $0 [KEY [PASSFILE]]" >&2
        exit 1
    fi

    ARGS+=("-in" "$KEY")
fi

if [[ -n "$PASS" ]]; then
    if [[ ! -r "$PASS" ]]; then
        echo "Usage: $0 [KEY [PASSFILE]]" >&2
        exit 1
    fi

    ARGS+=("-passin" "file:$PASS")
fi

openssl rsa "${ARGS[@]}" -pubout 2>/dev/null | \
    openssl rsa -pubin -noout -text | \
    sed -e '/Modulus:$/d;s/Public-Key: (\(.*\))/Modulus (\1):/'