注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

艾伯特的鸟屋

 
 
 

日志

 
 

OpenSSL应用实例3: RSA  

2014-11-18 13:54:41|  分类: applications |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

产生一对公钥和私钥
$openssl genrsa -out myrsa.pem 1024
$ cat myrsa.pem
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCwQIGSOAEijHRADKptvViLaLB7dadtgcMyv29KWckN3SpMV02p
fkGqLO9NcxSzz9S7xh0IxnynZ7oMWBQE0NBDQOStxLLOdi4p9LeHveud8H1QTB2U
PbuYS2ETbFu6Wy7eS5yCER2k4gLwL+FLB97OhVeLymGb7s+U9LrOfXULqQIDAQAB
AoGASpeCPrelA1IeAN1bY4Y26wkrZ5SrfxTj355VI0pMZKmtNRHdtFXSxIqv3D9Q
C6lxhuaZcxVNvCuR+ZdtIXyeJqRYks9TWOh3AZE89EWwYPs0JB5gUTklEEPAHhYm
02x78DrgmVVBe7Z7HUl3uWitUOUKZxop4bqmVwSMBXTGNAECQQDeuZ/PTGp9nq3q
kTpHaKf6f/KqNOFyRjRy8pa5wW8ctVi8wRmOPBYudgbn7YFJarNIdXPF4S3YRM7n
qi3Cw6XZAkEAypV24oOg7UOPKWWt8jkPZv1yIvBOuraAyGetTLu6fSuBEJWqUlfD
yr8pLvLNNe/YnP2+xyHhTxonWCGXo8TiUQJAaBPz8unxpWweN0vQIQht3qglnJYD
d+QIpGJqPrl+k7rGkcXmjEnVz7ZFueGJleYviz+fbyuvwa09xpIGukm02QJABc4e
qAMJm4LyGUeWonhMHrFokeO8/dC5BAUkjCxc/bU/b5A6Xz2wmKC9t2CxzLfgxy7m
RqKL6E5hjj74L3M24QJAIa2Y3wL2XDwSU6+p6v21JTuWPzmUl/ikuLfg9ovscY34
Uq0ieXRvm+XYeAhT6QOlu092ByEJrDQY6UyDwPdhOA==
-----END RSA PRIVATE KEY-----
$
导出公钥
$openssl rsa -in myrsa.pem -pubout -out myrsa_pub.pem
$cat myrsa_pub.pem
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwQIGSOAEijHRADKptvViLaLB7
dadtgcMyv29KWckN3SpMV02pfkGqLO9NcxSzz9S7xh0IxnynZ7oMWBQE0NBDQOSt
xLLOdi4p9LeHveud8H1QTB2UPbuYS2ETbFu6Wy7eS5yCER2k4gLwL+FLB97OhVeL
ymGb7s+U9LrOfXULqQIDAQAB
-----END PUBLIC KEY-----
$
$ openssl rsa -in myrsa.pem -text -noout
Private-Key: (1024 bit)
modulus:
    00:b0:40:81:92:38:01:22:8c:74:40:0c:aa:6d:bd:
    58:8b:68:b0:7b:75:a7:6d:81:c3:32:bf:6f:4a:59:
    c9:0d:dd:2a:4c:57:4d:a9:7e:41:aa:2c:ef:4d:73:
    14:b3:cf:d4:bb:c6:1d:08:c6:7c:a7:67:ba:0c:58:
    14:04:d0:d0:43:40:e4:ad:c4:b2:ce:76:2e:29:f4:
    b7:87:bd:eb:9d:f0:7d:50:4c:1d:94:3d:bb:98:4b:
    61:13:6c:5b:ba:5b:2e:de:4b:9c:82:11:1d:a4:e2:
    02:f0:2f:e1:4b:07:de:ce:85:57:8b:ca:61:9b:ee:
    cf:94:f4:ba:ce:7d:75:0b:a9
publicExponent: 65537 (0x10001)
privateExponent:
    4a:97:82:3e:b7:a5:03:52:1e:00:dd:5b:63:86:36:
    eb:09:2b:67:94:ab:7f:14:e3:df:9e:55:23:4a:4c:
    64:a9:ad:35:11:dd:b4:55:d2:c4:8a:af:dc:3f:50:
    0b:a9:71:86:e6:99:73:15:4d:bc:2b:91:f9:97:6d:
    21:7c:9e:26:a4:58:92:cf:53:58:e8:77:01:91:3c:
    f4:45:b0:60:fb:34:24:1e:60:51:39:25:10:43:c0:
    1e:16:26:d3:6c:7b:f0:3a:e0:99:55:41:7b:b6:7b:
    1d:49:77:b9:68:ad:50:e5:0a:67:1a:29:e1:ba:a6:
    57:04:8c:05:74:c6:34:01
prime1:
    00:de:b9:9f:cf:4c:6a:7d:9e:ad:ea:91:3a:47:68:
    a7:fa:7f:f2:aa:34:e1:72:46:34:72:f2:96:b9:c1:
    6f:1c:b5:58:bc:c1:19:8e:3c:16:2e:76:06:e7:ed:
    81:49:6a:b3:48:75:73:c5:e1:2d:d8:44:ce:e7:aa:
    2d:c2:c3:a5:d9
prime2:
    00:ca:95:76:e2:83:a0:ed:43:8f:29:65:ad:f2:39:
    0f:66:fd:72:22:f0:4e:ba:b6:80:c8:67:ad:4c:bb:
    ba:7d:2b:81:10:95:aa:52:57:c3:ca:bf:29:2e:f2:
    cd:35:ef:d8:9c:fd:be:c7:21:e1:4f:1a:27:58:21:
    97:a3:c4:e2:51
exponent1:
    68:13:f3:f2:e9:f1:a5:6c:1e:37:4b:d0:21:08:6d:
    de:a8:25:9c:96:03:77:e4:08:a4:62:6a:3e:b9:7e:
    93:ba:c6:91:c5:e6:8c:49:d5:cf:b6:45:b9:e1:89:
    95:e6:2f:8b:3f:9f:6f:2b:af:c1:ad:3d:c6:92:06:
    ba:49:b4:d9
exponent2:
    05:ce:1e:a8:03:09:9b:82:f2:19:47:96:a2:78:4c:
    1e:b1:68:91:e3:bc:fd:d0:b9:04:05:24:8c:2c:5c:
    fd:b5:3f:6f:90:3a:5f:3d:b0:98:a0:bd:b7:60:b1:
    cc:b7:e0:c7:2e:e6:46:a2:8b:e8:4e:61:8e:3e:f8:
    2f:73:36:e1
coefficient:
    21:ad:98:df:02:f6:5c:3c:12:53:af:a9:ea:fd:b5:
    25:3b:96:3f:39:94:97:f8:a4:b8:b7:e0:f6:8b:ec:
    71:8d:f8:52:ad:22:79:74:6f:9b:e5:d8:78:08:53:
    e9:03:a5:bb:4f:76:07:21:09:ac:34:18:e9:4c:83:
    c0:f7:61:38
$
rsa实例
$echo “/etc” > etcdir.txt
$openssl rsautl -encrypt -in etcdir.txt -pubin -inkey myrsa_pub.pem   -out etcdir.txt.encrypt
$openssl rsautl -decrypt -in etcdir.txt.encrypt -inkey myrsa.pem   -out etcdir.txt.decrypt
$diff etcdir.txt etcdir.txt.decrypt
$cat etcdir.txt.decrypt
/etc
$


  评论这张
 
阅读(308)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017