openssl generate private and public key code example

Example 1: Command to create the private key using the openssl command :

openssl genrsa -out private.pem 2048

Example 2: Command to create the private key and public using the openssl command :

openssl genrsa -out private.pem 2048
openssl rsa -in private_key.pem -outform PEM -pubout public.pem

Example 3: openssl create certificate with private key

-subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=examplebrooklyn.com"

Example 4: openssl create certificate with private key

---
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:Brooklyn
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Example Brooklyn Company
Organizational Unit Name (eg, section) []:Technology Division
Common Name (e.g. server FQDN or YOUR name) []:examplebrooklyn.com
Email Address []: