OpenSSL是一个强大的加密工具,它可以在Linux命令行中使用。以下是一些常用的OpenSSL命令:
openssl genrsa -out rsa_key.pem 2048
这将生成一个2048位的RSA私钥,并将其保存在名为rsa_key.pem
的文件中。
openssl req -new -key rsa_key.pem -out csr.pem
这将使用私钥rsa_key.pem
生成一个CSR,并将其保存在名为csr.pem
的文件中。在执行此命令时,您需要提供一些信息,如国家、组织名称等。
openssl x509 -req -days 365 -in csr.pem -signkey rsa_key.pem -out certificate.pem
这将使用私钥rsa_key.pem
签署CSR(csr.pem
),生成一个有效期为365天的自签名证书,并将其保存在名为certificate.pem
的文件中。
openssl x509 -in certificate.pem -outform DER -out certificate.der
这将把PEM格式的证书(certificate.pem
)转换为DER格式,并将其保存在名为certificate.der
的文件中。
openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.txt -pass pass:your_password
这将使用AES-256-CBC加密算法和指定的密码(your_password
)加密plaintext.txt
文件,并将加密后的内容保存在encrypted.txt
文件中。
openssl enc -d -aes-256-cbc -in encrypted.txt -out decrypted.txt -pass pass:your_password
这将使用相同的加密算法和密码(your_password
)解密encrypted.txt
文件,并将解密后的内容保存在decrypted.txt
文件中。
这只是OpenSSL命令行工具的一些基本用法。OpenSSL还提供了许多其他功能,如生成Diffie-Hellman密钥对、创建和管理PKCS#12证书存储等。要了解更多关于OpenSSL的信息,请参阅官方文档或输入openssl help
查看可用命令和选项。