-
Notifications
You must be signed in to change notification settings - Fork 39
/
rsa_genrsa_check.sh
executable file
·61 lines (38 loc) · 1.98 KB
/
rsa_genrsa_check.sh
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
set -eufx
# generate private key as PEM
openssl genrsa -provider tpm2 -verbose -out pubkey.pem 1024
# validate the generated file
openssl pkey -provider tpm2 -provider base -in pubkey.pem -check -noout
# print private key modulus
openssl rsa -provider tpm2 -provider base -in pubkey.pem -modulus -noout
# print components of the private key
openssl rsa -provider tpm2 -provider base -in pubkey.pem -text -noout
# convert PEM private key to DER
openssl pkey -provider tpm2 -provider base -in pubkey.pem -outform der -out pubkey.der
# read PEM and export public key as PEM
openssl pkey -provider tpm2 -provider base -in pubkey.pem -pubout -out testkey.pem
# print PEM public key modulus
openssl rsa -pubin -in testkey.pem -modulus -noout
# print components of the PEM public key
openssl rsa -pubin -in testkey.pem -text -noout
# read PEM from stdin and export public key as DER
cat pubkey.pem | openssl pkey -provider tpm2 -provider base -pubout -outform der -out testkey.der
# print DER public key modulus
openssl rsa -pubin -inform der -in testkey.der -modulus -noout
# print components of the DER public key
openssl rsa -pubin -inform der -in testkey.der -text -noout
# read DER and export public key as PEM
openssl rsa -provider tpm2 -provider base -in pubkey.der -inform der -RSAPublicKey_out -out testrsa.pem
# print PEM public key modulus
openssl rsa -RSAPublicKey_in -in testrsa.pem -modulus -noout
# print components of the PEM public key
openssl rsa -RSAPublicKey_in -in testrsa.pem -text -noout
# read DER and export public key as DER
openssl rsa -provider tpm2 -provider base -in pubkey.der -inform der -RSAPublicKey_out -outform der -out testrsa.der
# print PEM public key modulus
openssl rsa -RSAPublicKey_in -inform der -in testrsa.der -modulus -noout
# print components of the DER public key
openssl rsa -RSAPublicKey_in -inform der -in testrsa.der -text -noout
rm pubkey.pem pubkey.der testkey.pem testkey.der testrsa.pem testrsa.der