- 论坛徽章:
- 0
|
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;
}
结果不对, 哪位高手释疑, 感激之情如滔滔江水. |
|