码迷,mamicode.com
首页 > 其他好文 > 详细

RSA

时间:2018-04-01 01:04:31      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:print   font   pos   targe   key   href   分解   nss   publickey   

使用openssl解public.key

openssl rsa -pubin -text -modulus -in warmup -in pub.key

#coding:utf-8
from Crypto.PublicKey import RSA
import gmpy2
import binascii
import rsa
‘‘‘
# openssl rsa -pubin -text -modulus -in warmup -in pub.key
# Public-Key: (256 bit)
# Modulus:
#     00:c0:33:2c:5c:64:ae:47:18:2f:6c:1c:87:6d:42:
#     33:69:10:54:5a:58:f7:ee:fe:fc:0b:ca:af:5a:f3:
#     41:cc:dd
# Exponent: 65537 (0x10001)
# 分解n http://factordb.com/
# 分解n yasu软件 factor(n)
n = "00:c0:33:2c:5c:64:ae:47:18:2f:6c:1c:87:6d:42:33:69:10:54:5a:58:f7:ee:fe:fc:0b:ca:af:5a:f3:41:cc:dd"
res = (n.replace(":",""))
print int(res,16)
‘‘‘

r = open(pub.key).read()
# c = open(‘flag.enc‘).read().encode(‘hex‘)
# c = int(c,16)
# print c
# print r
pub = RSA.importKey(r)
# print pub
n = long(pub.n)
e = long(pub.e)
# print n
# print e
p = 285960468890451637935629440372639283459
q = 304008741604601924494328155975272418463
e = 65537
l = (p-1) * (q-1)
d = int(gmpy2.invert(e,l))

# m = pow(c,d,n)

privatekey = rsa.PrivateKey(n,e,d,p,q)
with open(flag.enc,rb) as f:
    print rsa.decrypt(f.read(),privatekey)

 

RSA

标签:print   font   pos   targe   key   href   分解   nss   publickey   

原文地址:https://www.cnblogs.com/hell0w/p/8684802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!