RSA
使用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)
利用私钥解密:
openssl rsautl -decrypt -in flag -inkey private.key -out flag_de
-in指定被加密的文件,-inkey指定私钥文件,-out为解密后的文件。