Asymmetric password and data signing with OpenSSL

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

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

THSe2J.png




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



THSe2J.png



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/

THSe2J.png






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


RQcebA.png





THSe2J.png






Next we will show our OpenSSL configuration file. For this, we use the following command;

Code:
set OPENSSL_CONF = C: \ openssl \ bin \ openssl.cfg


H91SSe.png


THSe2J.png



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


2cSRzT.png


THSe2J.png




After creating our Private Key, we can see our key in the Openssl / bin directory. We have completed our Private Key generation.

PxMNO5.png


THSe2J.png




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


7LyxeW.png


THSe2J.png


We created our Public Key in this way, and again we can see our public key in the openssl / bin directory.


URVyBd.png


THSe2J.png


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.
3xxPe6.png

71HHKz.png

THSe2J.png






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

aJ3CRQ.png


THSe2J.png



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,

U3ATGO.png


WB0z96.png


THSe2J.png




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.


BLa3TA.png

THSe2J.png


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

2fA8yO.png

THSe2J.png

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
OcH2CJ.png


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:
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.