Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Turbo-555

macrumors newbie
Original poster
Jun 20, 2008
8
0
Hello everybody,

I'm starting to work with cryptography on the iphone...

at the moment I'm trying to simply encrypt (and later decrypt a string) but ..when I run the app (on the device, an iphone) i get this message: "Program received signal: “EXC_BAD_ACCESS”."

which should mean...possibly problems with memory management right?
here the incriminated part of code:

uint8_t *pPlainText = (uint8_t*)"This is a test";
uint8_t *aCipherText;
size_t *iCipherLength = (size_t*)"1024";

status = SecKeyEncrypt( public, kSecPaddingNone, pPlainText,strlen( (char*)pPlainText ) + 1, aCipherText,iCipherLength );

public is a SecKeyRef containing the public key
:confused::confused:
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Glancing at the documentation, aCipherText should be allocated first, and iCipherLength shouldn't be a string. It needs to be a number. Here's an attempt at fixing it (not tested):
Code:
uint8_t *pPlainText = (uint8_t*)"This is a test";
uint8_t aCipherText[1024];
size_t iCipherLength = 1024;
status = SecKeyEncrypt(public,
                       kSecPaddingNone,
                       pPlainText,
                       strlen( (char*)pPlainText ) + 1,
                       aCipherText,
                       &iCipherLength);
 

Turbo-555

macrumors newbie
Original poster
Jun 20, 2008
8
0
Glancing at the documentation, aCipherText should be allocated first, and iCipherLength shouldn't be a string. It needs to be a number. Here's an attempt at fixing it (not tested):



that's what I was missing!!!

your solution works!!

thanks a lot!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.