Encrypt a File in Linux Ubuntu

On this day. I get a lot of knowledge of the lecturers I Cryptography network, namely regarding the Public Key Infrastructure. But for a discussion about this may be given in the next post. The posting of this time, I will give a tutorial for 1024 bit encrypt files. Why do only 1024 bit?? Because to generate a public key and privatenya I will use openssl. For more details, you can follow the steps below.

First, you enter Your root first. How to type
$ sudo su

Then after entering root, go into the folder that you created earlier in Your home. In this folder I have created is the folder test-pakiyan. You can also make it with
$ mkdir [the desired folder]

Next we generate a private key by typing
$ openssl genrsa -out rsaprivkey.pem -passout pass:stsn6 -des 1024

In this case we will get a private key that is the file "rsprivkey.pem", and the password is stsn6. then, we also have to generate the public key with the correspondent with our private key, type
$ openssl rsa -in rsaprivkey.pem -passin pass:stsn6 -pubout -out rsapublickey.pem

Our public key file named rsapublickey.pem.

After we already have these asymmetric key, we will try to encrypt a file (.txt) that we already have written therein. At this time, my files named "plain.txt" containing "denybinsarmangisi".

How to encrypt with type
$ openssl rsautl -encrypt -pubin -inkey rsapublickey.pem -in plain.txt -out cipher.txt

Later will appear a new file named "ciphers.txt" which is the result of encrypting a file .txt "plain". When you open it, the result will look like in the picture below.

To test the file "ciphers.txt" If the decrypted if same with files again, you can try it with type
$ openssl rsautl -decrypt -inkey rsaprivkey.pem -in cipher.txt -out plain.txt

From this will produce a file "plaincopy.txt", where after we open the contents are indeed the same as our original files i.e. "plain.txt".

so it can be stated the process of encryption and decryption of files using simple key to assimetris success.

Click here for Comments