#!/bin/bash

#  Copyright (c) 2016, Oracle and/or its affiliates.  All rights reserved.
#  
#  This software is dual-licensed to you under the MIT License (MIT) and
#  the Universal Permissive License (UPL).  See the LICENSE file in the root
#  directory for license terms.  You may choose either license, or both.
#  

echo "============================================================================================"
echo "Step 5: Generating RSA key pair using openssl"
echo "1. Generate a 2048-bit RSA private key: openssl genrsa -out private_key.pem 2048"
openssl genrsa -out private_key.pem 2048	
echo "2. Convert private Key to PKCS#8 format (so Java can read it): openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt"
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt
echo "3. Output public key portion in DER format (so Java can read it): openssl rsa -in private_key.pem -pubout -outform DER -out public_key.der"
openssl rsa -in private_key.pem -pubout -outform DER -out public_key.der