阅读量:3
OpenSSL是一个强大的开源工具,用于实现SSL和TLS协议,以及提供加密算法库
- 生成自签名证书:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
这将生成一个有效期为365天的自签名证书。
- 生成私钥:
openssl genpkey -algorithm RSA -out private_key.pem -aes256
这将生成一个使用AES-256加密的RSA私钥。
- 从PEM文件中提取公钥:
openssl rsa -in private_key.pem -pubout -out public_key.pem
这将提取PEM文件中的公钥并保存到public_key.pem。
- 将证书转换为PKCS#12格式:
openssl pkcs12 -export -in cert.pem -inkey key.pem -out keystore.p12 -name "mycert"
这将把证书和私钥转换为PKCS#12格式的keystore文件。
- 从PKCS#12文件中提取证书和私钥:
openssl pkcs12 -in keystore.p12 -out cert.pem -clcerts -nokeys
openssl pkcs12 -in keystore.p12 -out key.pem -nocerts -nodes
这将分别提取证书和私钥到cert.pem和key.pem文件。
- 生成Diffie-Hellman参数和密钥交换:
openssl dhparam -out dhparams.pem 2048
openssl genpkey -paramfile dhparams.pem -out dh_key.pem
这将生成Diffie-Hellman参数和密钥交换。
- 生成签名:
openssl dgst -sha256 -sign private_key.pem -out signature.bin data.txt
这将使用SHA-256算法和私钥对数据进行签名。
- 验证签名:
openssl dgst -sha256 -verify public_key.pem -signature signature.bin data.txt
这将使用公钥验证签名。
- 加密文件:
openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.txt -pass pass:mypassword
这将使用AES-256-CBC算法和给定的密码对文件进行加密。
- 解密文件:
openssl enc -aes-256-cbc -d -in encrypted.txt -out decrypted.txt -pass pass:mypassword
这将使用AES-256-CBC算法和给定的密码对加密文件进行解密。
这些只是OpenSSL命令的一部分功能。要了解更多关于OpenSSL的信息,请查阅官方文档或使用openssl help命令查看可用命令和选项。
以上就是关于“Linux中OpenSSL命令使用技巧”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm