Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:42+00:00 2026-05-31T13:22:42+00:00

I am developing an application for iPhone on Snow Leopard with Xcode 3.1 that

  • 0

I am developing an application for iPhone on Snow Leopard with Xcode 3.1 that receives from a restful web service an encrypted text in hexadecimal format with the algorithm AES 128-bit (CBC). The algorithm uses an initialization vector + secret key. How do I decrypt this text? Thanks to everyone for the tips that I will succeed in giving.

EDIT:
I get response from REST Server in hex AND crypted format,I try with this code but i receive always bad param error. Can you help me to find the error?
Is it possible that i firstly convert the string response into binary format?

      NSString *response = [request responseString];

      NSData *encryptedData = [response dataUsingEncoding: NSASCIIStringEncoding];
      NSString *key  = @"32charlength";
      NSString *iv   = @"16charlength";  
      NSData *unencryptedData = NULL;
      size_t unencryptedLength = [unencryptedData length];
      CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0, key, kCCKeySizeAES128, iv, [encryptedData bytes], [encryptedData length], unencryptedData, [encryptedData length], &unencryptedLength);     
      NSString *output = [[NSString alloc] initWithBytes:unencryptedData length:unencryptedLength encoding:NSUTF8StringEncoding];

      if (ccStatus == kCCSuccess) risultato.text = @"SUCCESS";
      else if (ccStatus == kCCParamError) risultato.text =  @"BAD PARAM";
      else if (ccStatus == kCCBufferTooSmall) risultato.text =  @"BUFFER TOO SMALL";
      else if (ccStatus == kCCMemoryFailure) risultato.text =  @"MEMORY FAILURE";
      else if (ccStatus == kCCAlignmentError) risultato.text =  @"ALIGNMENT";
      else if (ccStatus == kCCDecodeError) risultato.text =  @"DECODE ERROR";
      else if (ccStatus == kCCUnimplemented)  risultato.text = @"UNIMPLEMENTED";

EDIT2:
this function return BAD PARAM because haven’t the right buffer size where allocate decrypted data. I edit the function in this working way:

      NSData *encryptedData = [response dataUsingEncoding: NSASCIIStringEncoding];
      const void *key  = @"32charlength;
      uint8_t *iv      = @"16charlength";  
      char buffer[4*4096]; 
      memset(buffer, '\0', sizeof(buffer));
              size_t size = sizeof(buffer);
      CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt, 
                                         kCCAlgorithmAES128, 
                                         0, 
                                         key, 
                                         kCCKeySizeAES128, 
                                         iv, 
                                         [encryptedData bytes], 
                                         [encryptedData length], 
                                         buffer, 
                                         sizeof(buffer), 
                                         &size);

This function working for me.. thanks so much.

EDIT 23 MARCH——

Now the system work form me with 16 byte key size. Now i have a question, what i can do to implement 32 byte key size ? thanks so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:22:43+00:00Added an answer on May 31, 2026 at 1:22 pm

    This is possible using the CCCryptor functions included in the <CommonCrypto/CommonCryptor.h> header. Check man CCCryptor for the gory details, in your case it sounds like you can use a single call to CCCrypt() to decode the received data:

    CCCryptorStatus
    CCCrypt(CCOperation op, CCAlgorithm alg, CCOptions options, const void *key, size_t keyLength,
         const void *iv, const void *dataIn, size_t dataInLength, void *dataOut, size_t dataOutAvailable,
         size_t *dataOutMoved);
    

    Assuming you have the data to be decrypted in NSData *encryptedData you could try something like:

    char * key = "shouldbe16chars.";
    NSUInteger dataLength = [encryptedData length];
    uint8_t unencryptedData[dataLength + kCCKeySizeAES128];
    size_t unencryptedLength;
    
    CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0, key, kCCKeySizeAES128, NULL, [encryptedData bytes], dataLength, unencryptedData, dataLength, &unencryptedLength);
    NSString *output = [[NSString alloc] initWithBytes:unencryptedData length:unencryptedLength encoding:NSUTF8StringEncoding];
    

    This is untested, make sure you check the return value of CCCrypt for errors. Check the header file for details, it is well documented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an iPhone application. The application access some web service that aboug other
I am developing an application for iphone that will pick an image from photo
I'm developing an iphone app using PhoneGap 1.2.0 with Snow Leopard, Xcode 4.2 &
I am developing iPhone application and In that application I've one TableViewController , and
I'm developing one application for iphone using phone gap.I that I need to display
I am developing an iPhone application that persists data to a SQLite3 database. For
I am developing an iPhone application in which I am fetching data from a
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
I am developing application for iPhone environment for 1 year from now,In a recent
I am developing iPhone application which involves the frameworks available from iOS 3.2 (Core

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.