https://gist.github.com/dreikanter/c7e85598664901afae03fedff308736b
对称加密
AES:使用cqq作为密码。
$ openssl aes-256-cbc -salt -a -e -in plain.txt -out plain.txt.enc
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
*** WARNING : deprecated key derivation used.
cat plain.txt.enc
U2FsdGVkX1/dUM8eTeVwj+SXWGK3uR9vtS36WtnvNJL2GHBx2fKAoS9GQBuS4nWF
$ openssl aes-256-cbc -salt -a -d -in plain.txt.enc -out plain2.txt
enter aes-256-cbc decryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
$ ll plain2.txt
-rw-rw-r-- 1 cqq cqq 23 Mar 10 05:07 plain2.txt
$ cat plain2.txt
This is a test by cqq.
加解密文件也是一样。
非对称加密
首先生成用于加密的一对公私钥。
先生成私钥
openssl genrsa -aes256 -out private.key 8912
再从私钥中提取公钥。
openssl rsa -in private.key -pubout -out public.key
加密
openssl rsautl -encrypt -pubin -inkey public.key -in plain.txt -out plain.txt.encccc
解密
openssl rsautl -decrypt -inkey private.key -in plain.txt.encccc -out plain2.txt
解密之后跟原文一样。
加密文件
//TODO