免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5135 | 回复: 5
打印 上一主题 下一主题

在线请教路过的高手 crypto++ RSA解密问题. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-07 08:47 |只看该作者 |倒序浏览
I download crypto++5.1 and try to use it to decrypt a RSA(512)  encrpted message. Howerver, I got (d, n) instead of private key,  I know I shound use c^d%n to get plaintest, but I can't get right text. I don't know what's the problem.
The fowllowing is my codes

Decrypt(char * encryptedfilename)
{   
Integer d ("0x85A9244F6FE917A946235B3F06817C584707CD4D8699ED877CF54F705065264727D5FB6E2B140155CC81E1EA494CA5E73A958DA3E5E00B66905CA8E9F03B8E2B";     
   Integer n ("0xC87DB67727DDA37DE93508DE89C23A846A8BB3F449E6E44B3B6FF7287897B96C84336BE97236413344294612F2565AF877D18CA34415E3B97B267DD65569780D";     
  
   infile.open(encryptedfilename,ios::binary);
   int index=0;
   while (!infile.eof())
   {
    infile>;>;pdata[index++] ;
   }
   infile.close();
   pdata[index] = 0 ;

  p[0] = '0'; p[1] = 'x' ;
   HexEncoder hexEncoder1;
   hexEncoder1.Put(pdata,index);
   hexEncoder1.MessageEnd();
   hexEncoder1.Get((unsigned char*)(p+2),index*2);
  
  Integer c((char*)p);

    RSAFunction rsa;        //rsa
    rsa.Initialize(n,d);         
    plaintext = rsa.ApplyFunction(c);   

byte* buffer=new byte[1024];
for (int i=0;i<plaintext.ByteCount();i++)
  buffer[plaintext.ByteCount()-1-i]=plaintext.GetByte(i);
buffer[plaintext.ByteCount()]=0;
StringSource(buffer,plaintext.ByteCount(), true, new HexEncoder(new FileSink(cout)));
cout << endl; return 0;
}

结果不对, 哪位高手释疑, 感激之情如滔滔江水.

论坛徽章:
0
2 [报告]
发表于 2004-06-07 23:22 |只看该作者

在线请教路过的高手 crypto++ RSA解密问题.

Up

论坛徽章:
0
3 [报告]
发表于 2009-04-12 11:17 |只看该作者
RSAFunction::Initialize(const Integer &n, const Integer &e);要不是这样
InvertibleRSAFunction::void Initialize(const Integer &n, const Integer &e, const Integer &d);要不是这样
没有Initialize(const Integer &n, const Integer &d);这个函数

论坛徽章:
0
4 [报告]
发表于 2009-04-12 12:43 |只看该作者
不会用,我只会用OPENSSL里的RSA加解密

论坛徽章:
0
5 [报告]
发表于 2009-04-12 20:11 |只看该作者
可以这样做个函数封装:
RSA:: PrivateKey  GenerateRSAPrivateKey(const Integer &n, const Integer &d, const Integer &e)
{

        InvertibleRSAFunction params;
        params.Initialize(n,e,d);
        RSA:: PrivateKey m_privateKey( params );
        return m_privateKey;

}
RSA:: PublicKey  GenerateRSAPublicKey(const Integer &n, const Integer &e)
{
    RSAFunction params;
    params.Initialize(n,e);
        RSA:: PublicKey m_publicKey( params );
        return m_publicKey;
   
}

[ 本帖最后由 fansmore 于 2009-4-12 20:13 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2009-04-12 20:12 |只看该作者

回复 #5 fansmore 的帖子

调用时可以这样写:
m_privateKey=GenerateRSAPrivateKey(n, d, e);
m_publicKey=GenerateRSAPublicKey(n, e);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP