在Ubuntu上使用OpenSSL进行加密和解密,你可以使用以下命令:
加密:
openssl enc -aes-256-cbc -salt -in input_file.txt -out encrypted_file.enc -pass pass:your_password
这里,input_file.txt
是要加密的文件,encrypted_file.enc
是加密后的文件,your_password
是用于加密的密码。
解密:
openssl enc -d -aes-256-cbc -in encrypted_file.enc -out decrypted_file.txt -pass pass:your_password
这里,encrypted_file.enc
是要解密的文件,decrypted_file.txt
是解密后的文件,your_password
是用于解密的密码。
生成密钥对:
openssl req -x509 -newkey rsa:4096 -keyout private_key.pem -out public_key.pem -days 365
这里,private_key.pem
是生成的私钥文件,public_key.pem
是生成的公钥文件。
使用公钥加密:
openssl pkeyutl -encrypt -in input_file.txt -out encrypted_file.enc -pubin -inkey public_key.pem
这里,input_file.txt
是要加密的文件,encrypted_file.enc
是加密后的文件,public_key.pem
是公钥文件。
使用私钥解密:
openssl pkeyutl -decrypt -in encrypted_file.enc -out decrypted_file.txt -inkey private_key.pem
这里,encrypted_file.enc
是要解密的文件,decrypted_file.txt
是解密后的文件,private_key.pem
是私钥文件。
注意:在使用这些命令时,请确保替换文件名和密码。