256bit RSA公钥安全系数极低,只需要几分钟即可破解密文,本文综合其他文章记录了一次解密256bits RSA加密的密文的过程,仅作为备忘。

1.分解公钥,分解出n与e:

  1.1使用openssl(红色标记是e与n)

 qi@zhuandshao:~/download/iscc-ctf/RSA$ openssl rsa -pubin -text -modulus -in public.pem

 Public-Key: ( bit)

 Modulus:

 :a4:::de:fd::8b:::b4:e2:eb:1e:c9:

 bf::a6:1c:d9:c3:b5:a0:a7::::1e:eb:2f:

 b8::a7

13 Exponent: 65537 (0x10001)                #e
14
15 Modulus=A41006DEFD378B7395B4E2EB1EC9BF56A61CD9C3B5A0A73528521EEB2FB817A7 #n writing RSA key -----BEGIN PUBLIC KEY----- MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAKQQBt79N4tzlbTi6x7Jv1amHNnDtaCn NShSHusvuBenAgMBAAE= -----END PUBLIC KEY----- qi@zhuandshao:~/download/iscc-ctf/RSA$

1.2使用脚本

 from Crypto.PublicKey import RSA

 pub = RSA.importKey(open('xxx\public.pem').read())

 n = long(pub.n)

 e = long(pub.e)

 print n

 print e

2.使用msieve来对n来分解因式p、q:(红色标记部分)

 qi@zhuandshao:~/download/iscc-ctf/RSA$ msieve 0XA41006DEFD378B7395B4E2EB1EC9BF56A61CD9C3B5A0A73528521EEB2FB817A7 -v

 Msieve v. 1.54 (SVN )

 Wed May  :: 

 random seeds:  1225946d

 factoring  ( digits)

 no P-/P+/ECM available, skipping

 commencing quadratic sieve (-digit input)

 using multiplier of 

 using generic 32kb sieve core

 sieve interval:  blocks of size 

 processing polynomials in batches of 

 using a sieve bound of  ( primes)

 using large prime bound of  ( bits)

 using trial factoring cutoff of  bits

 polynomial 'A' values have  factors

 restarting with  full and  partial relations

  relations ( full +  combined from  partial), need 

 sieving complete, commencing postprocessing

 begin with  relations

 reduce to  relations in  passes

 attempting to read  relations

 recovered  relations

 recovered  polynomials

 attempting to build  cycles

 found  cycles in  passes

 distribution of cycle lengths:

 length  : 

 length  : 

 largest cycle:  relations

 matrix is  x  (5.3 MB) with weight  (29.92/col)

 sparse part has weight  (29.92/col)

 filtering completed in  passes

 matrix is  x  (4.0 MB) with weight  (33.55/col)

 sparse part has weight  (33.55/col)

 saving the first  matrix rows for later

 matrix includes  packed rows

 matrix is  x  (2.6 MB) with weight  (24.46/col)

 sparse part has weight  (17.67/col)

 commencing Lanczos iteration

 memory use: 2.7 MB

 lanczos halted after  iterations (dim = )

 recovered  nontrivial dependencies

87 p39 factor: 258631601377848992211685134376492365269------------------->p
88
89 p39 factor: 286924040788547268861394901519826758027------------------->q elapsed time :: qi@zhuandshao:~/download/iscc-ctf/RSA$

3.使用脚本来生成私钥文件(修改红色部分)

 import math

 import sys

 from Crypto.PublicKey import RSA

 keypair = RSA.generate(1024)

11 keypair.p = 258631601377848992211685134376492365269           #msieve求解的p
12
13 keypair.q = 286924040788547268861394901519826758027    #msieve求解的q     
14
15 keypair.e = 65537 #分解出的e keypair.n = keypair.p * keypair.q Qn = long((keypair.p-1) * (keypair.q-1)) i = 1 while (True): x = (Qn * i ) + 1 if (x % keypair.e == 0): keypair.d = x / keypair.e break i += 1 private = open('private.pem','w') private.write(keypair.exportKey()) private.close()

4.使用生成的privete.pem私钥文件对密文解密

 

  openssl rsautl -decrypt -in flag.enc -inkey private.pem -out flag

附录:

1.linux下安装msieve

sourceforgot上下载软件源代码包:

https://sourceforge.net/projects/msieve/

解压后

 $ cd msieve-code/

 $make

 to build:

 make all

 add 'WIN=1 if building on windows

 add 'WIN64=1 if building on 64-bit windows

 add 'ECM=1' if GMP-ECM is available (enables ECM)

 add 'CUDA=1' for Nvidia graphics card support

 add 'MPI=1' for parallel processing using MPI

 add 'BOINC=1' to add BOINC wrapper

 add 'NO_ZLIB=1' if you don't have zlib

 $ make all ECM= #根据自己的配置进行选择

应该会报错gmp.h不存在,安装高精度数学库就可以啦。

2.linux安装gmp(高精度数学库) 

环境:ubuntu
17.04

源代码:https://gmplib.org/

下载gmp-5.0.1的源代码,解压至gmp-5.0.1目录。

#lzip -d gmp-6.1..tar.lz
#tar -xvf gmp-6.1..tar

su切换至超级用户权限。
./configure
--prefix=/usr  --enable-cxx

提示:
checking
for suitable m4… configure: error:
 No
usable m4 in $PATH or /usr/5bin (see config.log for
reasons).
根据提示查看config.log日志文件,发现文件太大,何处找原因呢?
没有办法,直接google搜索上面的英文提示。
居然马上就找到了资料解决这个问题,原来是缺少m4软件包。
查了一下m4是一个通用的宏处理器,由Brian
Kernighan 和Dennis
Ritchie设计。
apt-get
install build-essential
m4
安装完毕,其中的build-essential是ubuntu下用来解决安装g++/gcc编译环境依赖关系的软件包。

开始编译,安装gmp数学库。

 ./configure --prefix=/usr  --enable-cxx
make
make check
make install

参考资料:

  1.256-bitRSA破解-实验吧

  2.[翻译]初学者向导―GGNFS和MSIEVE分解因数-『外文翻译』-看雪安全论坛:http://bbs.pediy.com/thread-156206.htm

  3.ubuntu10.4下安装和使用GMP高精度数学库:http://blog.csdn.net/bingqingsuimeng/article/details/12748341

通过公钥解密密文思路(256bits RSA)的更多相关文章

  1. RSA公钥文件解密密文的原理分析

    前言 最近在学习RSA加解密过程中遇到一个这样的难题:假设已知publickey公钥文件和加密后的密文flag,如何对其密文进行解密,转换成明文~~ 分析 对于rsa算法的公钥与私钥的产生,我们可以了 ...

  2. [WP8.1开发]RSA 使用BouncyCastle 公钥解密

    写应用的时候遇到个服务器返回私钥加密过的数据 ,然后要在客户端用公钥解密的需求 ,一直没找到方法,应用搁置了一个学期,多方搜索,结论就是.net没有实现公钥解密的方法,要自己实现,于是硬着头皮开始看B ...

  3. C# 与JAVA 的RSA 加密解密交互,互通,C#使用BouncyCastle来实现私钥加密,公钥解密的方法

    因为C#的RSA加密解密只有公钥加密,私钥解密,没有私钥加密,公钥解密.在网上查了很久也没有很好的实现.BouncyCastle的文档少之又少.很多人可能会说,C#也是可以的,通过Biginteger ...

  4. 基于私钥加密公钥解密的RSA算法C#实现

    RSA算法是第一个能同时用于加密和数字签名的算法,也易于理解和操作. RSA是被研究得最广泛的公钥算法,从提出到现在已近二十年,经历了各种攻击的考验,逐渐为人们接受,普遍认为是目前最优秀的公钥方案之一 ...

  5. 银联手机支付(.Net Csharp),3DES加密解密,RSA加密解密,RSA私钥加密公钥解密,.Net RSA 3DES C#

    前段时间做的银联支付,折腾了好久,拼凑的一些代码,有需要的朋友可以参考,本人.Net新手,不保证准确性! 这个银联手机支付没有SDK提供,技术支持也没有.Net的,真心不好搞! RSA加解密,这里有个 ...

  6. RSA不对称加密,公钥加密私钥解密,私钥加密公钥解密

    RSA算法是第一个能同时用于加密和数字签名的算法,也易于理解和操作. RSA是被研究得最广泛的公钥算法,从提出到现在已近二十年,经历了各种攻击的考验,逐渐为人们接受,普遍认为是目前最优秀的公钥方案之一 ...

  7. RSA,JAVA私钥加密,C#公钥解密

    做这个东西在坑里爬了3天才爬出来,记录下供园友参考.C#程序员一枚,项目需要和Java做数据交互,对方甩了段密文和一个CER证书给我,然后我要对其密文进行解密. RSA 非对称加密,对方用私钥加密,我 ...

  8. RSA加解密 私钥加密公钥解密 私加公解 && C++ 调用openssl库 的代码实例

    前提:秘钥长度=1024 ============================================== 对一片(117字节)明文加密  私加 ===================== ...

  9. python的rsa公钥解密方法

    示例: # -*- coding: UTF- -*- import M2Crypto import base64 #私钥加密,公钥解密 def pri_encrypt(msg, file_name): ...

随机推荐

  1. OpenCV学习笔记二:OpenCV模块一览

    注:本系列博客基于OpenCV 2.9.0.0 一,一览图: 二,模块: /* 基础库 */ 1,opencv_core(链接) ,opencv最基础的库.包含exception,point,rect ...

  2. python学习【第二篇】初识python

    python的安装 windows 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python27 3.配置环境变量 [右键计算机] ...

  3. 学生成绩管理系统【c】

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...

  4. 3673: 可持久化并查集 by zky

    3673: 可持久化并查集 by zky Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 2170  Solved: 978[Submit][Status ...

  5. 1503 猪和回文(DP)

    1503 猪和回文 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一只猪走进了一个森林.很凑巧的是,这个森林的形状是长方形的,有 ...

  6. 160822、关于javascrip ==(等号) 和===(恒等)判断

    说明 在JavaScript中,下面的值被当做假(false),除了下面列出的值,都被当做真(true): false null undefined 空字符串 数字 0 NaN //属性是代表非数字值 ...

  7. 巨蟒python全栈开发django9:一些知识点的汇总

    回顾上周内容: 题目: 1.人民出版社出版过的所有书籍的名字以及作者的姓名(三种写法,笔记中有两种写法) 2.手机以2开头的作者出版过的所有书籍名称以及出版社名称(三种写法,笔记中有1种写法) 1.聚 ...

  8. Spring 缓存注解@Cacheable 在缓存时候 ,出现了第一次进入调用 方法 ,第二次不调用的异常

    代码: @Override @Cacheable(value = CACHE_NAME, key = "'CartItemkey_'+#uId") public List<S ...

  9. php自定义函数: 下载远程文件 httpcopy

    <?php function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo( ...

  10. Connection cannot be null when 'hibernate.dialect' not set

    严重: Exception sending context initialized event to listener instance of class [org.springframework.w ...