开发者

Transforming a really large integer in Symbian descriptor-form to an unsigned char*

We're trying to implement RSA encryption in Symbian using the Open C/C++ library (rsa.h), and the 'RSA_public_encrypt' method:

buffSize = RSA_public_encrypt(maxSize, (unsigned char *) plainkey, (unsigned char *) cipherkey, rsa, RSA_NO_PADDING);

We created a public key with our own exponent and modulus and put that in the 'rsa'-object. Our plain text to be encrypted is a very large integer received in string form (so as a Symbian descriptor).

Ho开发者_JAVA百科wever, the plain text should be provided as an 'unsigned char*' to the encryption method. How can I transform the descriptor (plain text) to an 'unsigned char*' so that the encryption method interprets our plain text as a very large integer. Or for those not familiar with Symbian descriptors: how can I transform the plain text from a regular string (char *) to a value that the encryption interprets as a very large integer.

We already tried to provide the plain text in several ways, but the encryption text wasn't what it should have been (we compared this with results on other platforms which we verified was correct).

Any help is greatly appreciated.


You have to allocate (malloc) the plainkey and cipherkey variables and copy the unencrypted plain text string to cipherkey using lstrcpy or something similar in order to make this function work.

plainkey = malloc(PLAINKEY_SIZE);
cipherkey = malloc(CIPHERKEY_SIZE);
lstrcpy(plainkey, "12345...");
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);

you can also use unsigned char arrays:

unsigned char plainkey[PLAINKEY_SIZE] = "12345...";
unsigned char plainkey[CIPHERKEY_SIZE];
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);


The first argument to RSA_public_encrypt is flen and the second is from i.e. it will encrypt flen bytess from from.

Assuming you have a TDesC8 descriptor source you want to encrypt, call the function like this:

 RSA_public_encrypt(source.Length(), source.Ptr(), ... 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜