OpenSSL是一个功能强大的命令行工具,用于加密、解密、签名和验证数据。以下是一些常用的OpenSSL命令行使用技巧:
生成密钥对:
openssl genrsa -out private_key.pem 2048
openssl rsa -in private_key.pem -pubout -out public_key.pem
加密和解密文件:
openssl enc -aes-256-cbc -e -in input.txt -out encrypted.txt -k secretkey
openssl enc -d -aes-256-cbc -in encrypted.txt -out decrypted.txt -k secretkey
生成自签名证书:
openssl req -new -x509 -key private_key.pem -out certificate.pem -days 365
使用技巧:
-pass
选项来指定密码:openssl enc -aes-128-cbc -e -in input.txt -out encrypted.txt -pass pass:yourpassword
openssl enc -aes-128-cbc -e -in input.txt -out encrypted.txt -base64
-nosalt
选项在不使用盐值的情况下加密:openssl enc -aes-128-ecb -e -in input.txt -out encrypted.txt -nosalt -base64
查看支持的加密算法:
openssl list -cipher-commands
转换密钥格式:
openssl rsa -in private_key.pem -outform DER -out private_key.der
查看证书信息:
openssl x509 -in certificate.pem -text -noout