OpenSSL密钥相关命令
一. RSA PEM文件格式
- PEM私钥格式文件
-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- - PEM公钥格式文件
-----BEGIN PUBLIC KEY----- -----END PUBLIC KEY----- PEM RSAPublicKey公钥格式文件
-----BEGIN RSA PUBLIC KEY----- -----END RSA PUBLIC KEY-----二. OpenSSL密钥相关命令
生成密钥
openssl genrsa -out key.pem 1024 -out 指定生成文件,此文件包含公钥和私钥两部分,所以即可以加密,也可以解密 1024 生成密钥的长度- 提取PEM格式公钥
openssl rsa -in key.pem -pubout -out pubkey.pem -in 指定输入的密钥文件 -out 指定提取生成公钥的文件(PEM公钥格式) - 提取PEM RSAPublicKey格式公钥
openssl rsa -in key.pem -RSAPublicKey_out -out pubkey.pem -in 指定输入的密钥文件 -out 指定提取生成公钥的文件(PEM RSAPublicKey格式) - 公钥加密文件
openssl rsautl -encrypt -in input.file -inkey pubkey.pem -pubin -out output.file -in 指定被加密的文件 -inkey 指定加密公钥文件 -pubin 表面是用纯公钥文件加密 -out 指定加密后的文件 - 私钥解密文件
openssl rsautl -decrypt -in input.file -inkey key.pem -out output.file -in 指定需要解密的文件 -inkey 指定私钥文件 -out 指定解密后的文件