2010/7/12 Carlos Saldaña <saldana...@gmail.com> > unsigned char encrypted[2560] = { 0 }; > int resultEncrypt = 0; > > resultEncrypt = RSA_public_encrypt ( strlen(text) + 1 , (unsigned char > *)text, encrypted, rsa_rpu, RSA_PKCS1_OAEP_PADDING ); > NSLog(@"%d from encrypt.", resultEncrypt); > //This line prints 128 > NSLog(@"encrypted message %i", (int)encrypted); > //Here I get a large negative number (- 974687...) > > if (resultEncrypt == -1){ > printf("encryption failed "); > } > else{ > printf("Encryption success"); > } >
I don't know ObjC, but when it doesn't deviate too much from C/C++, then the %i (- 974687...) is you printing the address of 'encrypted' as an integer, which can be any kind of number on any platform, and that's not exactly informative. ;-) (Name of array variable functions as pointer/reference, when used without the [] index brackets) Anyway, to see the encrypted data, I'd suggest hexdumping the stuff like, for instance, so: printf("crypted data dump (len = %d):\n", resultEncrypt); for (int i = 0; i < resultEncrypt; i++) { printf("%02X ", encrypted[i]); } or whatever the equivalent of that bit of C code would read in ObjC/NS. (NSLog() ~ printf(), I take it?) Be reminded that the encryption process can only be truly called 'successful' iff you also happen to have code (and complementary key) which performs the /decryption/ process so that you get your original message a.k.a. 'plaintext' back. For that, your partners should have provided you with a key pair for testing purposes (or you might have received directions how to roll your own keypair in a way 100% compatible with theirs). -- Met vriendelijke groeten / Best regards, Ger Hobbelt -------------------------------------------------- web: http://www.hobbelt.com/ http://www.hebbut.net/ mail: g...@hobbelt.com mobile: +31-6-11 120 978 --------------------------------------------------