OpenSSL

加密與 SSL/TLS 工具套件

加密解密

AES-256-CBC 加密

openssl aes-256-cbc -in 123.txt -out encrypted_123

AES-256-CBC 解密

openssl aes-256-cbc -d -in encrypted_123 -out abc.txt

憑證操作

產生私鑰

openssl genrsa -out private.key 2048

產生 CSR

openssl req -new -key private.key -out certificate.csr

產生自簽憑證

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate.crt

查看憑證資訊

openssl x509 -in certificate.crt -text -noout

驗證憑證與私鑰匹配

openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in private.key | openssl md5

雜湊與校驗

MD5

openssl md5 filename

SHA256

openssl sha256 filename

連線測試

測試 SSL/TLS 連線

openssl s_client -connect example.com:443

查看伺服器憑證

openssl s_client -connect example.com:443 -showcerts