ubuntu

ubuntu上openssl加密解密怎么做

小樊
33
2025-09-27 20:35:13
栏目: 云计算

在Ubuntu上使用OpenSSL进行加密和解密,你可以使用以下命令:

  1. 对称加密(例如AES-256-CBC):

加密:

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 是用于解密的密码。

  1. 非对称加密(例如RSA):

生成密钥对:

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 是私钥文件。

注意:在使用这些命令时,请确保替换文件名和密码。

0
看了该问题的人还看了