OpenSSL是一个强大的开源工具,它可以在Linux命令行上用于处理加密和解密任务。以下是一些基本的OpenSSL命令行用法:
openssl genpkey -algorithm RSA -out rsa_key.pem -aes256
这条命令会生成一个2048位的RSA私钥,并将其保存到rsa_key.pem文件中。-aes256选项表示使用AES-256加密私钥。
openssl req -new -key rsa_key.pem -out csr.pem
这条命令会使用之前生成的私钥创建一个证书签名请求(CSR),并将其保存到csr.pem文件中。
openssl req -x509 -new -nodes -key rsa_key.pem -sha256 -days 3650 -out certificate.pem
这条命令会生成一个自签名的X.509证书,有效期为3650天,并将其保存到certificate.pem文件中。
openssl rsautl -decrypt -in encrypted_file.enc -out decrypted_file.txt -inkey rsa_key.pem
这条命令会使用私钥rsa_key.pem解密encrypted_file.enc文件,并将结果保存到decrypted_file.txt文件中。
openssl rsautl -encrypt -in plaintext_file.txt -out encrypted_file.enc -pubin -inkey public_key.pem
这条命令会使用公钥public_key.pem加密plaintext_file.txt文件,并将结果保存到encrypted_file.enc文件中。
openssl x509 -in certificate.pem -text -noout
这条命令会显示证书的详细信息,包括有效期、颁发者、主题等。
openssl rsa -in rsa_key.pem -check -noout
这条命令会检查私钥的有效性。
openssl x509 -in certificate.pem -outform DER -out certificate.der
这条命令会将PEM格式的证书转换为DER格式,并保存到certificate.der文件中。
openssl rand -base64 32
这条命令会生成一个32字节的随机字符串,并进行Base64编码。
openssl rand -out random_file.bin 256
这条命令会生成一个256字节的随机数文件random_file.bin。
这些是OpenSSL命令行的一些基本用法,实际应用中可能还有更多高级功能。建议查阅OpenSSL的官方文档以获取更详细的信息。