Kullanıcı1233
Kıdemli Üye
- 19 Tem 2011
- 4,371
- 12
Hello THT members,
I will show you how we can encrypt and sign the data with 2 keys (Private Key, Public Key) that we will create in this ********. We will use the OpenSSL tool when the subject is complete. I wish you good reading .. SUBJECTS
Definitions and Preparedness
Generating Public Key
Generating a Private Key
File Encryption Using Public Key
Deciphering an Encrypted File Using a Private Key
Signing a File with a Private Key
Verifying the File Signed with the Public Key
DEFINITIONS AND PREPARATION I want to introduce the subject by explaining the terms that we will work on in order to understand the
issue better.
Asymmetric Encryption: It is the encryption using two keys. We call these keys Private Key and Public Key. The public key allows the encrypted file to be verified, while the private key allows us to read the encrypted file.
Public Key: It is the key that provides the verification of the signed encrypted text.
Private Key: It is the key that enables the encrypted text to become original and the key holder can read the content.
We will do our encryption and signing operations using the OpenSSL tool. You can download the OpenSSL tool from the official site below;
Code:
https://www.openssl.org/source/
CREATING A CUSTOM KEY
After downloading our OpenSSL tool, we open the command line. And we go to the directory where our tool is installed on the command line. I put the installation files into the C directory and I get the following path
Code:
cd C: \ openssl \ bin
Next we will show our OpenSSL configuration file. For this, we use the following command;
Code:
set OPENSSL_CONF = C: \ openssl \ bin \ openssl.cfg
Let's determine the name and length of our Private key. I will set the length to 1024. You can do this by 2048, 4096 to be safer according to your preference. We enter the command below;
Code:
openssl.exe genrsa -out PrivateKeyTHT.pem 1024
After creating our Private Key, we can see our key in the Openssl / bin directory. We have completed our Private Key generation.
CREATING A GENERAL KEY We
will use our private key to generate the public key. For this, we use the following command;
Code:
openssl.exe rsa -in PrivateKeyTHT.pem -out PublicKeyTHT.pem -outform PEM -pubout
We created our Public Key in this way, and again we can see our public key in the openssl / bin directory.
FILE ENCRYPTION USING THE GENERAL KEY
Now that we have created both keys, we can now start encrypting. I created a text file called "blackcoderdeneme.txt" in the openssl / bin directory. And I wrote my content I want to encrypt in my text file.
Now, let's start the encryption process on the command line again. In the command below, let's determine the file to be encrypted (blackcoderden.t.txt), public key (PublicKeyTHT.pem) and what will be the encrypted new file name (encrypted.enc);
Code:
openssl.exe rsautl -encrypt -inkey PublicKeyTHT.pem -pubin-of blackcoderexperiment.txt -out encrypted.enc
Right after that, we can see our encrypted .enc file in the openssl / bin directory. When we open the file with a notebook, we see that it is encrypted as follows,
USING SPECIAL KEY decipher the encrypted file
now encrypted using the private key file is decrypted Let us. We enter the command below;
Code:
openssl.exe rsautl -decrypt -inkey PrivateKey.pem of encryptedTest.enc
Then we see the original of the text encrypted on the command line as below.
FILE SIGNING WITH PRIVATE KEY
We will now sign our previously created "blackcoderdeneme.txt" file using our private key. The name of our new signed file is "signed.txt". We enter the command below;
openssl.exe rsautl -sign -inkey PrivateKeyTHT.pem-of blackcoderden.t.txt> signed.txt
Right after that, we open our "signed.txt" file, which is created in the openssl / bin directory. And we see it is signed as below
VERIFYING THE FILE SIGNED WITH THE GENERAL KEY
Now let's verify the file we signed with our public key and reach the original text. We enter the following command in the command line;
Code:
openssl.exe rsautl -verify -inkey PublicKey.pem -pubin -in signedTest.txt
As you can see below, we have reached the original text by verifying our signed file on the command line.
I will show you how we can encrypt and sign the data with 2 keys (Private Key, Public Key) that we will create in this ********. We will use the OpenSSL tool when the subject is complete. I wish you good reading .. SUBJECTS
Definitions and Preparedness
Generating Public Key
Generating a Private Key
File Encryption Using Public Key
Deciphering an Encrypted File Using a Private Key
Signing a File with a Private Key
Verifying the File Signed with the Public Key
DEFINITIONS AND PREPARATION I want to introduce the subject by explaining the terms that we will work on in order to understand the
issue better.
Asymmetric Encryption: It is the encryption using two keys. We call these keys Private Key and Public Key. The public key allows the encrypted file to be verified, while the private key allows us to read the encrypted file.
Public Key: It is the key that provides the verification of the signed encrypted text.
Private Key: It is the key that enables the encrypted text to become original and the key holder can read the content.
We will do our encryption and signing operations using the OpenSSL tool. You can download the OpenSSL tool from the official site below;
Code:
https://www.openssl.org/source/
CREATING A CUSTOM KEY
After downloading our OpenSSL tool, we open the command line. And we go to the directory where our tool is installed on the command line. I put the installation files into the C directory and I get the following path
Code:
cd C: \ openssl \ bin
Next we will show our OpenSSL configuration file. For this, we use the following command;
Code:
set OPENSSL_CONF = C: \ openssl \ bin \ openssl.cfg
Let's determine the name and length of our Private key. I will set the length to 1024. You can do this by 2048, 4096 to be safer according to your preference. We enter the command below;
Code:
openssl.exe genrsa -out PrivateKeyTHT.pem 1024
After creating our Private Key, we can see our key in the Openssl / bin directory. We have completed our Private Key generation.
CREATING A GENERAL KEY We
will use our private key to generate the public key. For this, we use the following command;
Code:
openssl.exe rsa -in PrivateKeyTHT.pem -out PublicKeyTHT.pem -outform PEM -pubout
We created our Public Key in this way, and again we can see our public key in the openssl / bin directory.
FILE ENCRYPTION USING THE GENERAL KEY
Now that we have created both keys, we can now start encrypting. I created a text file called "blackcoderdeneme.txt" in the openssl / bin directory. And I wrote my content I want to encrypt in my text file.
Now, let's start the encryption process on the command line again. In the command below, let's determine the file to be encrypted (blackcoderden.t.txt), public key (PublicKeyTHT.pem) and what will be the encrypted new file name (encrypted.enc);
Code:
openssl.exe rsautl -encrypt -inkey PublicKeyTHT.pem -pubin-of blackcoderexperiment.txt -out encrypted.enc
Right after that, we can see our encrypted .enc file in the openssl / bin directory. When we open the file with a notebook, we see that it is encrypted as follows,
USING SPECIAL KEY decipher the encrypted file
now encrypted using the private key file is decrypted Let us. We enter the command below;
Code:
openssl.exe rsautl -decrypt -inkey PrivateKey.pem of encryptedTest.enc
Then we see the original of the text encrypted on the command line as below.
FILE SIGNING WITH PRIVATE KEY
We will now sign our previously created "blackcoderdeneme.txt" file using our private key. The name of our new signed file is "signed.txt". We enter the command below;
openssl.exe rsautl -sign -inkey PrivateKeyTHT.pem-of blackcoderden.t.txt> signed.txt
Right after that, we open our "signed.txt" file, which is created in the openssl / bin directory. And we see it is signed as below
VERIFYING THE FILE SIGNED WITH THE GENERAL KEY
Now let's verify the file we signed with our public key and reach the original text. We enter the following command in the command line;
Code:
openssl.exe rsautl -verify -inkey PublicKey.pem -pubin -in signedTest.txt
As you can see below, we have reached the original text by verifying our signed file on the command line.
Moderatör tarafında düzenlendi: