File: rsa_genrsa_check.sh

package info (click to toggle)
tpm2-openssl 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,172 kB
  • sloc: ansic: 6,075; sh: 5,400; makefile: 152
file content (61 lines) | stat: -rwxr-xr-x 2,032 bytes parent folder | download | duplicates (2)
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