在Ubuntu下,OpenSSL是一个非常强大的加密工具包,提供了很多命令行工具来执行各种加密任务。以下是一些常用的OpenSSL命令:
版本信息:
openssl version
生成密钥对:
openssl genrsa -out rsa_key.pem 2048
openssl rsa -in rsa_key.pem -pubout -out rsa_pub.pem
生成证书签名请求(CSR):
openssl req -new -key rsa_key.pem -out csr.pem
自签名证书:
openssl req -x509 -new -nodes -key rsa_key.pem -sha256 -days 365 -out certificate.pem
查看证书信息:
openssl x509 -in certificate.pem -text -noout
加密文件:
openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.bin -pass pass:yourpassword
解密文件:
openssl enc -d -aes-256-cbc -in encrypted.bin -out decrypted.txt -pass pass:yourpassword
生成Diffie-Hellman参数:
openssl dhparam -out dhparams.pem 2048
生成ECDH密钥对:
openssl ecparam -name secp384r1 -genkey -noout -out ecdh_key.pem
生成ECDSA签名:
openssl dgst -sha256 -sign private_key.pem -out signature.bin data.txt
验证ECDSA签名:
openssl dgst -sha256 -verify public_key.pem -signature signature.bin data.txt
生成随机数:
openssl rand -base64 32
生成伪随机数文件:
openssl rand -out random_file.bin 1024
查看私钥信息:
openssl rsa -in rsa_key.pem -check -noout
转换证书格式:
openssl x509 -in certificate.pem -outform DER -out certificate.der
openssl x509 -in certificate.der -inform DER -outform PEM -out certificate.pem
这些命令只是OpenSSL功能的一部分,OpenSSL还提供了许多其他命令和选项来处理各种加密任务。你可以使用openssl help
命令来查看所有可用的命令和选项。