使用OpenSSL實現安全的文件傳輸通常涉及以下幾個步驟:
生成密鑰對:
openssl genpkey -algorithm RSA -out rsa_key.pem 2048
openssl rsa -pubout -in rsa_key.pem -out rsa_key.pub
加密文件:
openssl rsautl -encrypt -pubin -inkey rsa_key.pub -in plaintext.txt -out encrypted_file.enc
傳輸加密文件:
解密文件:
openssl rsautl -decrypt -inkey rsa_key.pem -in encrypted_file.enc -out decrypted_file.txt
首先,生成一對RSA密鑰,包括公鑰和私鑰。
openssl genpkey -algorithm RSA -out rsa_key.pem 2048
openssl rsa -pubout -in rsa_key.pem -out rsa_key.pub
rsa_key.pem
是私鑰文件。rsa_key.pub
是公鑰文件。使用接收方的公鑰加密文件。假設接收方的公鑰文件名為 recipient_rsa_key.pub
。
openssl rsautl -encrypt -pubin -inkey recipient_rsa_key.pub -in plaintext.txt -out encrypted_file.enc
recipient_rsa_key.pub
是接收方的公鑰文件。plaintext.txt
是要加密的明文文件。encrypted_file.enc
是加密后的文件。將加密后的文件傳輸到接收方??梢允褂肧CP、SFTP或其他安全的文件傳輸方法。
scp encrypted_file.enc user@remote_host:/path/to/destination
接收方使用自己的私鑰解密文件。
openssl rsautl -decrypt -inkey rsa_key.pem -in encrypted_file.enc -out decrypted_file.txt
rsa_key.pem
是接收方的私鑰文件。encrypted_file.enc
是接收到的加密文件。decrypted_file.txt
是解密后的明文文件。通過以上步驟,可以實現使用OpenSSL進行安全的文件傳輸。