• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
      • From: Dave Camp <email@hidden>
References: 
 >[iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality (From: Tharindu Madushanka <email@hidden>)

  • Prev by Date: Re: Window Resize with Animator Proxy: Window Contents Jump Around
  • Next by Date: Windowed Video
  • Previous by thread: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
  • Next by thread: Re: [iPhone] Encrypting data of an iPhone Application / Converting J2ME App functionality
  • Index(es):
    • Date
    • Thread