在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
是私鑰文件。
注意:在使用這些命令時,請確保替換文件名和密碼。