Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 26, 2008, 03:58 PM   #1
Turbo-555
macrumors newbie
 
Join Date: Jun 2008
problems using SecKeyEncrypt

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
Turbo-555 is offline   0 Reply With Quote
Old Aug 26, 2008, 04:18 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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);
kainjow is offline   0 Reply With Quote
Old Aug 26, 2008, 06:17 PM   #3
Turbo-555
Thread Starter
macrumors newbie
 
Join Date: Jun 2008
Quote:
Originally Posted by kainjow View Post
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!
Turbo-555 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Problems with Radeon 5870 on my Mac Pro using Boot Camp uelef Mac Pro 9 Jul 14, 2012 12:55 PM
Problem using Dreamweaver to connect to MySQL database jh100000 Web Design and Development 2 Feb 22, 2006 04:57 AM
problem using firewire with my powerbook... proverbs PowerPC Macs 7 Sep 19, 2005 04:21 AM
dvd burning problem using Toast 6.1 henrydog Mac Applications and Mac App Store 5 Jul 21, 2005 10:50 PM
Audio problems using Skype MacCharrúa Macintosh Computers 5 Aug 24, 2004 12:10 PM


All times are GMT -5. The time now is 09:54 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC