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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:20:59+00:00 2026-05-11T04:20:59+00:00

I need to encrypt a string on the iPhone and send it to a

  • 0

I need to encrypt a string on the iPhone and send it to a .Net web service for decryption. I am able to encrypt/decrypt on the iPhone and with .Net, but the encrypted strings from the iPhone cannot be decrypted by .Net. The error I get is ‘Padding is invalid and cannot be removed.’

The .Net code is from: http://blog.realcoderscoding.com/index.php/2008/07/dot-net-encryption-simple-aes-wrapper/

The iPhone code uses the sample code from: http://nootech.wordpress.com/2009/01/17/symmetric-encryption-with-the-iphone-sdk/

AFAIK my key settings are the same:

result.BlockSize = 128; // iPhone: kCCBlockSizeAES128 result.KeySize = 128; // kCCBlockSizeAES128 result.Mode = CipherMode.CBC; result.Padding = PaddingMode.PKCS7; // kCCOptionPKCS7Padding 

I tried different ways of generating ciphertext. hello/hello is:

e0PnmbTg/3cT3W+92CDw1Q== in .Net

yrKe5Z7p7MNqx9+CbBvNqQ== on iPhone

and ‘openssl enc -aes-128-cbc -nosalt -a -in hello.txt -pass pass:hello’ generates: QA+Ul+r6Zmr7yHipMcHSbQ==

Update: I’ve posted the working code for this here.

  • 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. 2026-05-11T04:20:59+00:00Added an answer on May 11, 2026 at 4:20 am

    At the very least, you are using differing initialization vectors (IV).

    • The .Net code uses the key for IV.

      private static AesCryptoServiceProvider GetProvider(byte[] key) {     //Set up the encryption objects     AesCryptoServiceProvider result = new AesCryptoServiceProvider();     byte[] RealKey = Encryptor.GetKey(key, result);     result.Key = RealKey;     result.IV = RealKey;     return result; }

      and

      private static byte[] GetKey(byte[] suggestedKey, AesCryptoServiceProvider p) {     byte[] kRaw = suggestedKey;     List kList = new List();     for (int i = 0; i < p.LegalKeySizes[0].MinSize; i += 8 )     {         kList.Add(kRaw[i % kRaw.Length]);     }     byte[] k = kList.ToArray();     return k; }

      which should probably be: kList.Add(kRaw[(i / 8) % kRaw.Length]);. Otherwise a key whose length % 8 == 0 will use the same letter repeatedly, doh!

      Thus the IV (and key) used by .Net is: hleolhleolhleolh. This is not part of the API, but rather due to the wrapper code that you pointed at (which has a serious bug in it…).

    • The iPhone code uses 0 for IV.

      // Initialization vector; dummy in this case 0's. uint8_t iv[kChosenCipherBlockSize]; memset((void *) iv, 0x0, (size_t) sizeof(iv));
    • openssl by default prepends a randomly generated salt (which is why the output is longer!).

    The openssl output is more secure since it is prepending a random initialization vector. It looks like the first few bytes of the base64 decoded string is ‘Salted__’. You can also ask openssl to not use a salt (-nosalt) and / or provide an IV (-iv).

    Essentially, openssl, .Net, and the iPhone are using the same encryption, you just need to be careful how you initialize the APIs with the encryption key and the initialization vector.

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

Sidebar

Related Questions

I need to encrypt a string on the iPhone and send it to a
I need to encrypt and decrypt a querystring in ASP.NET. The querystring might look
I need to encrypt a string (from a text area) that will also be
I need to encrypt a string using MySQL's AES_ENCRYPT function, then attach that encrypted
I need fast and simple way to encrypt/decrypt a lot of String data. I
We need to PGP encrypt files and send them over FTP to a third
need ask you about some help. I have web app running in Net 2.0.
in function need key to encrypt string without mcrypt libraly in php function encrypt($str,
I have a .NET application. I need to store a text value encrypted in
I want to encrypt a string using AES with my own key. But I'm

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.