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 7653037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:55:27+00:00 2026-05-31T11:55:27+00:00

I have problem converting .NET C# AES 128 Encryption to iOS (iPhone). Everything generated

  • 0

I have problem converting .NET C# AES 128 Encryption to iOS (iPhone). Everything generated correctly except the last block. The final call to xfrm.TransformFinalBlock generate differently than what I got from iOS code (using CCCryptorFinal). I am using the same parameter for BlockSize, Key and IV. What else am I missing? Thank you.

Obj-C

CCCryptorStatus ccStatus = kCCSuccess;


CCCryptorRef thisEncipher = NULL;

// Create and Initialize the crypto reference.
ccStatus = CCCryptorCreate(kCCEncrypt, 
                           kCCAlgorithmAES128, 
                           kCCOptionPKCS7Padding, 
                           szKey,
                           kCCKeySizeAES128, 
                           iv, 
                           &thisEncipher
                           );

// Calculate byte block alignment for all calls through to and including final.
int bufferPtrSize = CCCryptorGetOutputLength(thisEncipher, InputLength, true);

unsigned char *szResult = (unsigned char *)malloc(bufferPtrSize+1);

memset(szResult, 0x00, bufferPtrSize+1);

while (dataEncrypted < dataToEncrypt)
{
    bool final = (dataToEncrypt - dataEncrypted) <= lrcEncryptionBlockSize;

    if (final)
    {
        // Finalize everything to the output buffer.

        ccStatus = CCCryptorFinal(thisEncipher,
                                  szResult + dataEncrypted,
                                  bufferPtrSize - dataEncrypted,
                                  pOutSize
                                  );


        dataEncrypted += *pOutSize;

        for(int c=0;c<dataEncrypted;++c)
        {
            printf("\n%d => %d\n", c, szResult[c]);
        }

        success = true;
        break;
    }
    else
    {

    // Actually perform the encryption or decryption.
        ccStatus = CCCryptorUpdate( thisEncipher,
                                   szInput+cb,
                                   lrcEncryptionBlockSize,
                                   szResult+dataEncrypted,
                                   bufferPtrSize - dataEncrypted,
                                   pOutSize
                                   );   


        dataEncrypted += *pOutSize;

        cb += lrcEncryptionBlockSize;

    }
}

if (thisEncipher) {
    (void) CCCryptorRelease(thisEncipher);
    thisEncipher = NULL;
}

C#

        AesManaged aesAlg = new AesManaged();
        ICryptoTransform xfrm;

        aesAlg.IV = GenerateIV();
        aesAlg.Key = "1111111111111111";
        aesAlg.BlockSize = 128;

        xfrm = aesAlg.CreateEncryptor();

        while (dataEncrypted < dataToEncrypt)
        {
            bool final = (dataToEncrypt - dataEncrypted) <= lrcEncryptionBlockSize;
            int nbytes = !final ? lrcEncryptionBlockSize : (int)(dataToEncrypt - dataEncrypted); 

            if (final)
            {
                byte[] finalblock = xfrm.TransformFinalBlock(message, cb, nbytes);
                Buffer.BlockCopy(finalblock, 0, message, cb, lrcEncryptionBlockSize);
                success = true;
                break;
            }
            else
            {
                dataEncrypted += (uint)xfrm.TransformBlock(message, cb, nbytes, message, cb);
                cb += lrcEncryptionBlockSize;
            }
        }

        xfrm.Dispose();
        aesAlg.Clear();
  • 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-31T11:55:29+00:00Added an answer on May 31, 2026 at 11:55 am

    If only the last block differs, the difference is probably that they use different padding. The first example uses PKCS7, but I cant see what the second one uses.

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

Sidebar

Related Questions

I have a weird problem in converting a string to double in .NET 3.5.
I'm working on converting NerdDinner to Spark and have everything except the mobile views
I have a problem converting a string binary to a decimal I was using
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
I am having trouble converting some code from VB6 to VB.NET (I don't have
Note, I have found the solution to my problem. Please see below. I'm converting
I have problem, when converting Windows application from .NET2.0 to .NET3.5. I do this
I have started converting my simple website to ASP.NET MVC, just to mess around

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.