采采流水

An Essay Concerning Human Understanding

Encryption

Qiangua / 2019-12-16


Symmetric Cryptography

openssl aes-256-cbc -a -e -in file-in.txt -inkey key.txt -out file-out.txt
openssl aes-256-cbc -a -d -in file-in.txt -inkey key.txt -out file-out.txt

Asymmetric Cryptography

generate private key

openssl genrsa -out private.pem 1024

generate public key from private key

openssl rsa -in private.pem -pubout -out public.pem

encrypt file with public key

openssl rsautl -encrypt -in test.org -inkey public.pem -pubin -out encrypted.inc

decrypt file wiht private key

openssl rsatul -decrypt -in encrypted.inc -inkey private.pem -out decrypted.org

GNUGPG

GNUGPG is a practical terminal tool for encryption. Here are two typical commands

gpg --encrypt -r ID test.txt
gpg --decrypt test.txt.gpg --out-put test.de.txt

An effective usage:

alias gpge='gpg --encrypt -r USER_ID | $(fzf)'
alias gpgd='gpg --decrypt | $(fzf)'