Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
- Subject: Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
- From: Tharindu Madushanka <email@hidden>
- Date: Thu, 16 Jul 2009 15:43:10 +0530
Hi,
The Java application uses RC4 Encryption. Could some one help me to encrypt
a String with CommonCrypto. I think we can use CCCrypt function to do this.
Can anyone point some way.
I have worked on below code to encrypt a string. But it did not seem to be
working.
- (NSString*) encodeToRC4:(NSString*)plainText {
const void *vplainText;
size_t plainTextBufferSize;
plainTextBufferSize = [plainText length];
vplainText = (const void *) [plainText UTF8String];
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes = 0;
bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) &
~(kCCBlockSize3DES - 1);
bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
// memset((void *) iv, 0x0, (size_t) sizeof(iv));
NSString *key = @"r#@^$&%$*&*^(*";
NSString *initVec = @"init Vec";
const void *vkey = (const void *) [key UTF8String];
const void *vinitVec = (const void *) [initVec UTF8String];
ccStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmRC4,
kCCOptionPKCS7Padding,
vkey,
kCCAlgorithmRC4,
vinitVec,
vplainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
if (ccStatus == kCCSuccess) NSLog(@"SUCCESS");
else if (ccStatus == kCCParamError) return @"PARAM ERROR";
else if (ccStatus == kCCBufferTooSmall) return @"BUFFER TOO SMALL";
else if (ccStatus == kCCMemoryFailure) return @"MEMORY FAILURE";
else if (ccStatus == kCCAlignmentError) return @"ALIGNMENT";
else if (ccStatus == kCCDecodeError) return @"DECODE ERROR";
else if (ccStatus == kCCUnimplemented) return @"UNIMPLEMENTED";
NSString *result;
NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr
length:(NSUInteger)movedBytes];
result = [[NSString alloc] initWithData:myData
encoding:NSASCIIStringEncoding];
return result;
}
Please kindly have a look at how should I correct this.
Thank you,
Tharindu Madushanka
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden