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

  • Home
  • SEARCH
  • 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 6627081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:58:13+00:00 2026-05-25T21:58:13+00:00

I’ve checked all the related Stack Overflow questions. Also checked the links in that

  • 0

I’ve checked all the related Stack Overflow questions. Also checked the links in that answers but didn’t got any usable solution.

Here is my php script and I’ve nothing to do with this script (as I can’t change the script).

function encrypt($message,$secretKey) {
return base64_encode(
    mcrypt_encrypt(
        MCRYPT_RIJNDAEL_256,
        $secretKey,
        $message,
        MCRYPT_MODE_ECB
    )
 );
}

I’m unable to decrypt it in Objective C. I’ve used a number of Categories like Strong Encryption for Cocoa / Cocoa Touch etc, also I followed this question How do I do base64 encoding on iOS?

Here is the objective C codes that I used for decryption (found in cocoa-aes Category NSData+AES.h)

- (NSData *)AESDecryptWithPassphrase:(NSString *)pass
{
    NSMutableData *ret = [NSMutableData dataWithCapacity:[self length]];
    unsigned long rk[RKLENGTH(KEYBITS)];
    unsigned char key[KEYLENGTH(KEYBITS)];
    const char *password = [pass UTF8String];
    for (int i = 0; i < sizeof(key); i++)
        key[i] = password != 0 ? *password++ : 0;

    int nrounds = rijndaelSetupDecrypt(rk, key, KEYBITS);
    unsigned char *srcBytes = (unsigned char *)[self bytes];
    int index = 0;
    while (index < [self length])
    {
        unsigned char plaintext[16];
        unsigned char ciphertext[16];
        int j;
        for (j = 0; j < sizeof(ciphertext); j++)
        {
            if (index >= [self length])
                break;

            ciphertext[j] = srcBytes[index++];
        }
        rijndaelDecrypt(rk, nrounds, ciphertext, plaintext);
        [ret appendBytes:plaintext length:sizeof(plaintext)];
        NSString* s = [[NSString alloc] initWithBytes:plaintext length:sizeof(plaintext) encoding:NSASCIIStringEncoding];
        NSLog(@"%@",s);
    }
    return ret;
}

Also I tried this decoder

- (NSData*) aesDecryptWithKey:(NSString *)key initialVector:(NSString*)iv
{
    int keyLength = [key length];
    if(keyLength != kCCKeySizeAES128)
    {
        DebugLog(@"key length is not 128/192/256-bits long");

        ///return nil;
    }

    char keyBytes[keyLength+1];
    bzero(keyBytes, sizeof(keyBytes));
    [key getCString:keyBytes maxLength:sizeof(keyBytes) encoding:NSUTF8StringEncoding];

    size_t numBytesDecrypted = 0;
    size_t decryptedLength = [self length] + kCCBlockSizeAES128;
    char* decryptedBytes = malloc(decryptedLength);

    CCCryptorStatus result = CCCrypt(kCCDecrypt, 
                                     kCCAlgorithmAES128 , 
                                     (iv == nil ? kCCOptionECBMode | kCCOptionPKCS7Padding : kCCOptionPKCS7Padding),
                                     keyBytes, 
                                     keyLength, 
                                     iv,
                                     [self bytes], 
                                     [self length],
                                     decryptedBytes, 
                                     decryptedLength,
                                     &numBytesDecrypted);

    if(result == kCCSuccess){
        NSData* d=[NSData dataWithBytesNoCopy:decryptedBytes length:numBytesDecrypted];
        NSLog(@"%@",[NSString stringWithUTF8String:[d bytes]]);
        return d;
    }
    free(decryptedBytes);
    return nil;
}
  • 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-25T21:58:14+00:00Added an answer on May 25, 2026 at 9:58 pm

    From the looks of it, that php function does two things.

    1. mcrypt using MCRYPT_RIJNDAEL_256
    2. base64 encodes the output of (1)

    That would by why simply using base64 doesn’t work. I’m going to guess from the name that MCRYPT_RIJNDAEL_256 is just AES 256.

    Hope that helps.

    Edit:

    The code you added above looks ok. You just have to base64 decode the data first.

    The php script does this:

    1. aes encrypt
    2. base64 encode

    So you want to do this in your cocoa app:

    1. base64 decode
    2. aes decrypt

    If you’re having trouble, you might want to play around and see if you can get cocoa to do the same thing as the php script: encrypt and base64 encode the data. If you can get the output of your encryption function to be the same as the output of the php encryption function, you’re in a good place to get it decrypting.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.