Difference between revisions of "OpenSSL: encrypt decrypt file"

From OnnoWiki
Jump to navigation Jump to search
Line 2: Line 2:
  
  
 +
==Encrypt File==
  
 +
Contoh perintahnya
  
Linux has plenty of powerful encryption software, but what can you use if you just want to secure a couple files quickly? The OpenSSL toolkit works well for this. It comes installed with Ubuntu and can provide stronger encryption than you would ever need.
+
openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc
  
This is the basic command to encrypt a file:
+
Dimana,
  
openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc
+
* openssl - perintah untuk OpenSSL tookit
 +
* aes-256-cbc - encryption cipher yang digunakan. 256bit AES digunakan oleh pemerintah US untuk encrypt informasi top secret level.
 +
* -a - encrypted output akan di encode base64, jadi bisa di lihat di text editor / copy paste di e-mail.
 +
* -salt - menambahkan kekuatan encryption & harus selalu digunakan.
 +
* -in secrets.txt - input file yang akan di encrypt.
 +
* -out secrets.txt.enc - output file hasil encrypt.
  
How does this work?
+
Anda akan ditanya password untuk encrypt.
  
    openssl is the command for the OpenSSL toolkit.
+
==Decrypt file==
    aes-256-cbc is the encryption cipher to be used. (256bit AES is what the United States government uses to encrypt information at the Top Secret level.)
 
    -a means that the encrypted output will be base64 encoded, this allows you to view it in a text editor or paste it in an email. This is optional.
 
    -salt adds strength to the encryption and should always be used.
 
    -in secrets.txt specifies the input file.
 
    -out secrets.txt.enc specifies the output file.
 
    You will be prompted for a password.
 
  
It’s not much use unless you can decrypted it:
+
openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
  
openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
+
Dimana,
  
    -d decrypts data.
+
* -d - decrypt data.
    -a tells OpenSSL that the encrypted data is in base64.
+
* -a - encrypted data adalah base64.
    -in secrets.txt.enc specifies the data to decrypt.
+
* -in secrets.txt.enc - input file / data yang akan di decrypt.
    -out secrets.txt.new specifies the file to put the decrypted data in.
+
* -out secrets.txt.new - output file / data hasil decrypt.
  
Try out OpenSSL by decrypting this string (the password is pass):
+
==Cara lain==
  
U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A=
+
Jika kita mempunyai data yang di encrypt berikut (passwordnya = pass)
  
You can paste it into a text file and use the commands above, or use this command instead:
+
U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A=
 
 
echo U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A= | openssl aes-256-cbc -d -a
 
 
 
See the OpenSSL man page for more detail on what it can do.
 
 
 
 
 
==Lebih Sederhana==
 
 
 
 
 
 
 
 
 
This is the top answer to your question from google: http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl/
 
 
 
Encrypt:
 
 
 
openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc
 
 
 
Decrypt:
 
 
 
openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
 
 
 
But this does not make use of the public key infrastructure at all, so a bit like hammering in a nail with a screwdriver :-)
 
  
 +
Kita bisa juga menggunakan CLI berikut ini,
  
 +
echo U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A= | openssl aes-256-cbc -d -a
  
  

Revision as of 19:56, 7 June 2017

sumber: http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl/


Encrypt File

Contoh perintahnya

openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc

Dimana,

  • openssl - perintah untuk OpenSSL tookit
  • aes-256-cbc - encryption cipher yang digunakan. 256bit AES digunakan oleh pemerintah US untuk encrypt informasi top secret level.
  • -a - encrypted output akan di encode base64, jadi bisa di lihat di text editor / copy paste di e-mail.
  • -salt - menambahkan kekuatan encryption & harus selalu digunakan.
  • -in secrets.txt - input file yang akan di encrypt.
  • -out secrets.txt.enc - output file hasil encrypt.

Anda akan ditanya password untuk encrypt.

Decrypt file

openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new

Dimana,

  • -d - decrypt data.
  • -a - encrypted data adalah base64.
  • -in secrets.txt.enc - input file / data yang akan di decrypt.
  • -out secrets.txt.new - output file / data hasil decrypt.

Cara lain

Jika kita mempunyai data yang di encrypt berikut (passwordnya = pass)

U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A=

Kita bisa juga menggunakan CLI berikut ini,

echo U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A= | openssl aes-256-cbc -d -a


Referensi