在 Ubuntu 中,您可以使用 OpenSSL 命令行工具來加密和解密文件。以下是一些基本的 OpenSSL 加密和解密命令:
使用對稱加密(例如 AES-256-CBC):
openssl enc -aes-256-cbc -salt -in input_file -out encrypted_file
-aes-256-cbc
:指定使用 AES-256-CBC 加密算法。-salt
:添加鹽值以增強安全性。-in input_file
:指定要加密的輸入文件。-out encrypted_file
:指定輸出的加密文件。執行命令后,系統會提示您輸入一個密碼。這個密碼將用于加密和解密文件。
使用公鑰加密(例如 RSA):
openssl rsautl -encrypt -pubin -inkey public_key.pem -in input_file -out encrypted_file
-encrypt
:指定加密操作。-pubin
:指定使用公鑰進行加密。-inkey public_key.pem
:指定公鑰文件的路徑。-in input_file
:指定要加密的輸入文件。-out encrypted_file
:指定輸出的加密文件。使用對稱加密(例如 AES-256-CBC):
openssl enc -d -aes-256-cbc -in encrypted_file -out decrypted_file
-d
:指定解密操作。-aes-256-cbc
:指定使用 AES-256-CBC 解密算法。-in encrypted_file
:指定要解密的加密文件。-out decrypted_file
:指定輸出的解密文件。執行命令后,系統會提示您輸入之前用于加密的密碼。
使用私鑰解密(例如 RSA):
openssl rsautl -decrypt -inkey private_key.pem -in encrypted_file -out decrypted_file
-decrypt
:指定解密操作。-inkey private_key.pem
:指定私鑰文件的路徑。-in encrypted_file
:指定要解密的加密文件。-out decrypted_file
:指定輸出的解密文件。通過這些命令,您可以在 Ubuntu 系統中使用 OpenSSL 工具來加密和解密文件。