View Full Version : Problem in crypto :: RSA

21st March 2009, 13:49
I am writing a client software in QT 4.5 Commercial edition that need to send rsa encrypted data to server.
Steps are these:
1. get public key from server. The server gives (mod,exp) pair and nothing else
2. I need to encrypt data using "basic rsa" using the (mod,exp) and send to the server.

I am doing this to encrypt:

QString eee("22640209");//exp: got from server

QString mmm("95033496681677513042303794296510796923484007896833 482880191206334940729008671");//mod:got from server

QCA::BigInteger exp11(eee);
QCA::BigInteger mod11(mmm);

public_key = new QCA::RSAPublicKey(mod11,exp11,"rsa");

QCA::SecureArray data = "27712887867";
QCA::SecureArray sarray = public_key->encrypt(data,QCA::EncryptionAlgorithm::EME_PKCS1v1 5);

QString sss(sarray.toByteArray());
QString rstr = QCA::arrayToHex(sarray.toByteArray());

But, the problem is, the result never matches with the expected result (from a working java applicaton for same purpose which uses Bouncy Castle)

The correct output for the message "22640209" should be "7fcbaf7722eed6bf8914a924ac03de7e825d492f10a1487c84 eb5d94989c5e91"

I am stuck and I have a deadline coming.

Any help is welcome.

Sarwar Erfan

21st March 2009, 15:24
What encryption mode are you using? Maybe the two applications use different modes?

21st March 2009, 19:01
Thanks for your reply.
How do I change encryption mode in qt crypto?

21st March 2009, 21:40
I don't know much about QCA, but according to the documentation QCA::Cipher (http://api.kde.org/kdesupport-api/kdesupport-apidocs/qca/html/classQCA_1_1Cipher.html) provides a Mode enum, so you can probably use this class to create a cipher with the mode your server is expecting.

If you are not sure what that mode would be, have a look at the Java code. If it is some non-standard mode, it should be set somewhere in the code. Otherwise, it would be the default that BouncyCastle uses, so you should look at it's documentation to find out what that default is.