openssl命令行工具简介

 

 

原文链接: http://www.cnblogs.com/aLittleBitCool/archive/2011/09/22/2185418.html

首先介绍下命令台下openssl工具的简单使用:

生成一个密钥:
openssl genrsa -out test.key 1024
这里-out指定生成文件的。需要注意的是这个文件包含了公钥和密钥两部分,也就是说这个文件即可用来加密也可以用来解密。后面的1024是生成密钥的长度。

openssl可以将这个文件中的公钥提取出来:
openssl rsa -in test.key -pubout -out test_pub.key
-in指定输入文件,-out指定提取生成公钥的文件名。

至此,我们手上就有了一个公钥,一个私钥(包含公钥)。现在可以将用公钥来加密文件了。
我在目录中创建一个hello的文本文件,然后利用此前生成的公钥

加密文件:
openssl rsautl -encrypt -in hello -inkey test_pub.key -pubin -out hello.en
-in指定要加密的文件,-inkey指定密钥,-pubin表明是用纯公钥文件加密,-out为加密后的文件。

解密文件:
openssl rsautl -decrypt -in hello.en -inkey test.key -out hello.de
-in指定被加密的文件,-inkey指定私钥文件,-out为解密后的文件。

至此,一次加密解密的过程告终。在实际使用中还可能包括证书,这个以后有机会再说~

 

 

原文地址:https://www.cnblogs.com/huhu0013/p/4793988.html