在Ubuntu下,OpenSSL是一個非常強大的加密工具庫,它提供了許多命令行工具來執行各種加密任務。以下是一些常用的OpenSSL命令:
生成密鑰對
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout -out public.key
生成證書簽名請求(CSR)
openssl req -new -key private.key -out certificate.csr
自簽名證書
openssl req -x509 -new -nodes -key private.key -sha256 -days 365 -out certificate.crt
查看證書信息
openssl x509 -in certificate.crt -text -noout
加密文件
openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.bin
openssl enc -d -aes-256-cbc -in encrypted.bin -out decrypted.txt
生成Diffie-Hellman參數和密鑰交換
openssl dhparam -out dhparams.pem 2048
openssl genpkey -paramfile dhparams.pem -out dhprivatekey.pem
openssl pkey -in dhprivatekey.pem -pubout -out dhpublickey.pem
SSL/TLS客戶端和服務器測試
openssl s_client -connect example.com:443
openssl s_server -www -port 8443
生成和驗證簽名
openssl dgst -sha256 -sign private.key -out signature.bin document.txt
openssl dgst -sha256 -verify public.key -signature signature.bin document.txt
創建和管理PKCS#12文件(PFX)
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out certificate.crt
openssl pkcs12 -in certificate.pfx -nocerts -out private.key
生成隨機數據
openssl rand -out randombytes.bin 32
這些命令只是OpenSSL功能的一小部分。OpenSSL非常強大,可以進行復雜的加密操作、協議測試、證書管理等。在使用這些命令時,請確保你了解它們的作用以及如何安全地使用它們。如果你是初學者,建議從簡單的命令開始,并逐步深入了解每個命令的選項和用法。