openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html


rsautl是rsa的工具,相当于rsa、dgst的部分功能集合,可用于生成数字签名、验证数字签名、加密和解密文件

pkeyutl是非对称加密的通用工具,大体上和rsautl的用法差不多,所以此处只解释rsautl。

openssl rsautl [-in file] [-out file] [-inkey file] [-pubin] [-certin] [-passin arg] [-sign] [-verify] [-encrypt] [-decrypt] [-hexdump]

openssl pkeyutl [-in file] [-out file] [-sigfile file] [-inkey file] [-passin arg] [-pubin] [-certin] [-sign] [-verify] [-encrypt] [-decrypt] [-hexdump]

共同的选项说明:
-in file:指定输入文件
-out file:指定输出文件
-inkey file:指定密钥输入文件,默认是私钥文件,指定了"-pubin"则表示为公钥文件,使用"-certin"则表示为包含公钥的证书文件
-pubin:指定"-inkey file"的file是公钥文件
-certin:使用该选项时,表示"-inkey file"的file是包含公钥的证书文件
-passin arg:传递解密密码。若验证签名时实用的公钥或私钥文件是被加密过的,则需要传递密码来解密。密码的格式见"openssl 密码格式"
【功能选项:】
-sign:签名并输出签名结果,注意,该选项需要提供RSA私钥文件
-verify:使用验证签名文件
-encrypt:使用公钥加密文件
-decrypt:使用私钥解密文件
【输出格式选项:】
-hexdump:以hex方式输出 openssl pkeyutl选项说明:
sigfile file:待验证的签名文件

rsautl命令的用法和rsa、dgst不太一样。首先,它的前提是已经有非对称密钥,所有的命令操作都用到公钥或私钥来处理;再者,该命令使用-in选项来指定输入文件,而不像dgst一样可以把输入文件放在命令的结尾;最后,该命令使用的密钥文件、签名文件、证书文件都通过-inkey选项指定,再通过各功能的选项搭配来实现对应的功能。

注意rsautl和pkeyutl的缺陷是默认只能对短小的文件进行操作,否则将报类似如下的错误信息。

:error:0406C06E:rsa routines:RSA_padding_add_PKCS1_type_1:data too large for key size:rsa_pk1.c::

因为这两个工具签名和验证签名的功能和openssl dgst命令差不多,且自身又有缺陷,所以就不举例说明。此处仅给出对短小文件的非对称加密和解密示例。

(1).使用公钥加密b.txt文件,注意待加密文件b.txt必须是短小文件,且不建议使用-hexdump输出,否则解密时可能超出文件的长度。

[root@xuexi tmp]# openssl genrsa -out genrsa.pri   # 生成私钥

[root@xuexi tmp]# openssl rsa -in genrsa.pri -pubout -out rsa.pub   # 从私钥中提取公钥

[root@xuexi tmp]# openssl rsautl -encrypt -in b.txt -out b_crypt.txt -inkey rsa.pub -pubin

查看非对称加密后的文件b_crypt.txt。

[root@xuexi tmp]# cat b_crypt.txt
H[]=p?I,:=)Iڪ;Yx٩,vbot@xuexi tmp]#

(2).使用私钥解密b_crypt.txt文件。

[root@xuexi tmp]# openssl rsautl -decrypt -in b_crypt.txt -out b_decrypt.txt -inkey genrsa.pri

[root@xuexi tmp]# cat b_decrypt.txt
UUID=d505113c-daa6-4c17-8b03-b3551ced2305 swap swap defaults

6.openssl rsautl和openssl pkeyutl的更多相关文章

  1. openssl rsautl和openssl pkeyutl(文件的非对称加密)

    openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html rsautl是rsa的工具,相当于rsa.dgst的部分功能集合,可用于生成 ...

  2. (8) openssl rsautl(签名/验证签名/加解密文件)和openssl pkeyutl(文件的非对称加密)

    rsautl是rsa的工具,相当于rsa.dgst的部分功能集合,可用于生成数字签名.验证数字签名.加密和解密文件. pkeyutl是非对称加密的通用工具,大体上和rsautl的用法差不多,所以此处只 ...

  3. Openssl rsautl命令

    一.简介 rsautl指令能够使用RSA算法签名,验证身份,加密/解密数据 二.语法 openssl rsautl [-in file] [-out file] [-inkey file] [-pas ...

  4. 3.openssl speed和openssl rand

    (1).openssl speed 测试加密算法的性能. 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-c ...

  5. php开启openssl的方法,openssl安装

    php开启openssl的方法,openssl安装 2014年10月10日 8312次浏览 什么是openssl? 关于openssl,我说的不如百度百科齐全,还是看看百度百科的解释吧!http:// ...

  6. openssl speed和openssl rand

    openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 1.1 openssl speed 测试加密算法的性能. 支持的算法有: o ...

  7. OpenSSL主配置文件openssl.cnf

    虽说配置文件很多设置不用修改就能直接使用,但是了解它是配置openssl相关事项所必须的.而且要实现复杂多功能,必然要对配置相关了然于心. 1.man config 该帮助文档说明了openssl.c ...

  8. ambari2.6.50 openssl 版本问题:SSLError: Failed to connect. Please check openssl library versions. Openssl error upon host registration

    I'm trying to register hostnames in Ambari but getting the error below. We tried to run yum update o ...

  9. 【openssl】利用openssl完成X509证书和PFX证书之间的互转

    利用openssl完成X509证书和PFX证书之间的互转 # OpenSSL的下载与安装: 1.下载地址: 官方网址—— https://www.openssl.org/source/ OpenSSL ...

随机推荐

  1. 真机测试-Please enter a different string错误解决

    错误原因是这个bundle ID已经被占用了,这是想到的是要重置测试证书,那么则需要去修改Bundle identifier,因为测试证书是以Bundle identifier为基准的,修改后运行,重 ...

  2. [LeetCode] 14. Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. public class ...

  3. Adobe 软件防止联网激活更改Hosts文件

    来自为知笔记(Wiz) 附件列表

  4. Linux Epoll相关知识

    其实在Linux下设计并发网络程序,向来不缺少方法,比如典型的Apache模型(Process Per Connection,简称PPC),TPC(Thread PerConnection)模型,以及 ...

  5. C语言中,定义的含义?声明的含义?它们之间的区别是什么?

    在C语言中,对于定义和声明,也许我们非常的熟悉,但不一定真正的了解! 定义的含义:所谓定义,就是创建(编译器)一个对象,为这个对象分配一块内存空间并取名,也就是我们平常所说的变量名或对象名,一旦这个名 ...

  6. Allegro 快捷键设置

    一.快捷键设置 Allegro可以通过修改env文件来设置快捷键,这对从其它软件如AD或PADS迁移过来的用户来说,可以沿用以前的操作习惯,还是很有意义的. Allegro的变量文件一共有2个:一个是 ...

  7. 关于margin的问题

    昨晚是第一天,现在来说说margin的这个存在的问题吧, 嗯,就是当你碰到 <div class="max-box"> <div class="box1 ...

  8. 可提高工作效率的 PL/SQL Developer 设置

    1.将Window List 列表展示出来并保存当前布局 ①Tools-->Windows List (展示窗口列表) ②Window-->Save Layout (保存当前布局) 2.设 ...

  9. 强大的commons

    在此之前对commons包了解的不多,最常用的就是StringUtils.isBlack(str)来取代if(str !=null && str.lenght()>1)的判断,昨 ...

  10. 华硕Z97-A主板声卡设置

    $ vim /usr/share/alsa/alsa.conf ## defaults# # show all name hints also for definitions without hint ...