使用Linux OpenSSL加密文件是一個相對簡單的過程。以下是一些常用的命令和方法:
openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.bin
-aes-256-cbc:指定使用AES-256-CBC加密算法。-salt:添加鹽值以增加安全性。-in plaintext.txt:指定要加密的輸入文件。-out encrypted.bin:指定加密后的輸出文件。openssl enc -d -aes-256-cbc -in encrypted.bin -out decrypted.txt
-d:表示解密操作。openssl genpkey -algorithm RSA -out rsa_key.pem -pkeyopt rsa_keygen_bits:2048
-algorithm RSA:指定使用RSA算法。-out rsa_key.pem:指定生成的私鑰文件。-pkeyopt rsa_keygen_bits:2048:指定RSA密鑰的長度為2048位。openssl rsa -pubout -in rsa_key.pem -out rsa_pubkey.pem
-pubout:提取公鑰。-in rsa_key.pem:指定私鑰文件。-out rsa_pubkey.pem:指定輸出的公鑰文件。openssl rsautl -encrypt -pubin -inkey rsa_pubkey.pem -in plaintext.txt -out encrypted.bin
-encrypt:表示加密操作。-pubin:使用公鑰進行加密。-inkey rsa_pubkey.pem:指定公鑰文件。-in plaintext.txt:指定要加密的輸入文件。-out encrypted.bin:指定加密后的輸出文件。openssl rsautl -decrypt -inkey rsa_key.pem -in encrypted.bin -out decrypted.txt
-decrypt:表示解密操作。-inkey rsa_key.pem:指定私鑰文件。-in encrypted.bin:指定要解密的輸入文件。-out decrypted.txt:指定解密后的輸出文件。openssl enc -aes-256-cbc -salt -pbkdf2 -in plaintext.txt -out encrypted.bin
-pbkdf2:使用PBKDF2算法來增加安全性。openssl enc -d -aes-256-cbc -pbkdf2 -in encrypted.bin -out decrypted.txt
通過以上方法,你可以使用Linux OpenSSL輕松地加密和解密文件。