How to Crafting a private and also Public Key
Tags: security, hosting
Published: 2024-01-14 14:56:26

---
title: How to Crafting a private and also Public Key
published: true
date: 2024-01-01 20:07:58 UTC
tags: Security,Hosting
canonical_url: https://blog.bajonczak.com/creating-a-public-provate-and-public-key-with-the-windows-terminal/
---

 ![How to Crafting a private and also Public Key](https://images.unsplash.com/photo-1572435555646-7ad9a149ad91?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wxMTc3M3wwfDF8c2VhcmNofDZ8fGVuY3J5cHRpb258ZW58MHx8fHwxNzAzOTY1NzM1fDA&ixlib=rb-4.0.3&q=80&w=2000)

For a separate Blogpost, I need to generate a Public Key. So before we can generate a Public Key, we must generate a Private key. Let me first introduce the key types and let me tell s.th. about the advantages about this.

# What is a public and private key?

The Public and private keys are fundamental components of asymmetric encryption, in a widely used cryptographic system. In this system, each user has a pair of keys: a public key that is shared openly, and a private key that is kept confidential.

The public key is used for encryption, allowing anyone to send encrypted messages to the key owner. However, only the corresponding private key can decrypt these messages. This ensures secure communication and data exchange in various online transactions, such as secure email communication, digital signatures, and online banking.

The advantage of using public-key cryptography lies in its ability to establish secure communication channels without the need for both parties to share a secret key beforehand. This eliminates the challenges associated with key distribution in symmetric-key systems and enhances the overall security of digital interactions.

Public key infrastructure (PKI) further extends the utility of public and private key pairs by providing a framework for managing and validating keys in a secure manner.

In the next short chapters I will introduce you, how I generated a public and private key.

# How To generate the Private Key

For generating the privaste key, we must install openssl. Better is to use any WSL System

In this you must install then openssl (for example on my ubuntu image)

```
apt-get install openssl
```

Then you can create the certificate, please pay attention to get onto the shared drive like c. So go to /mnt/c to access the c-Drive from Windows. while you changed the location, you will execute the follwowing command

```
openssl genrsa -out privatekey.pem 2048
```

This generates this output

![How to Crafting a private and also Public Key](https://blog.bajonczak.com/content/images/2023/12/image-15.png)

After that you have your own private key. The content from the pem-File look like this

![How to Crafting a private and also Public Key](https://blog.bajonczak.com/content/images/2023/12/image-16.png)
_,_

No I'm not crazy, this key I generated only for demo purpose ;).

# Generate the public key

You can now create the public key with this. That's not a big deal, this can be done with the following command:

```
openssl rsa -in privatekey.pem -outform PEM -pubout -out publickey.pem

```

The result looks like this

![How to Crafting a private and also Public Key](https://blog.bajonczak.com/content/images/2023/12/image-17.png)

Now you have two files

- privatekey.pem 
- publickey.pem 

# Conslusion

This Blogpost gives you a small and simple step-by-step manual to create a public key. So with this, you can e.g. sign your blog posts or add the publickey to your Github account. So now your content can be identified with your public key.