#!/bin/bash
function title_print() {
terminal_width=$(stty size | cut -d' ' -f2)
title=$1
title_length=$(echo $title | wc -L)
pre_length=$((($terminal_width - $title_length) / 2 - 1))
yes "#" | sed $pre_length'q' | tr -d '\n'
echo -n " "$title" "
yes "#" | sed $pre_length'q' | tr -d '\n'
echo ''
}
openssl genrsa -out rsa_private_key.pem 2048 >>/dev/null 2>&1
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
openssl pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt -out pkcs8_private_key.pem
ssh-keygen -f rsa_public_key.pem -i -mPKCS8 >rsa_public_key.pub
KEY=$(sed '1d;$d' pkcs8_private_key.pem | tr -d '\n')
PUB=$(sed '1d;$d' rsa_public_key.pem | tr -d '\n')
title_print "private_key"
echo $KEY
title_print "public_key"
echo $PUB
title_print "RSA_private_key"
cat rsa_private_key.pem
title_print "RSA_public_key"
cat rsa_public_key.pub
# rm -f rsa_private_key.pem pkcs8_private_key.pem rsa_public_key.pem rsa_public_key.pub