1

I am using the StringEncryption.m library in iOS to encrypt messages, and then decode them on a .Net project.

For 99.9% of messages, the encryption / decryption process works. However, there is a particular message that the iOS app sends which always results in a "Padding is invalid" error on the .Net project.

The problem message is 800 bytes long. If i force it to be 799 or 801 bytes, the encryption / decryption works.

Both sides are using CBC and the iOS solution uses PKCS7 padding. Any ideas?

Jonathan Smith
  • 2,390
  • 1
  • 34
  • 60
  • What padding are you using in .Net? – atk Jun 14 '12 at 13:26
  • What is the offending message? – Paddy Jun 14 '12 at 13:27
  • The .Net padding is the default (PKCS7) – Jonathan Smith Jun 14 '12 at 13:32
  • I cant post the offending message as it contains private business information. It is an xml message. – Jonathan Smith Jun 14 '12 at 13:32
  • 1
    @JonathanSmith - Come up with a different message. You should also post the C# code that decrypts the message. If you cannot provide us the information we need to answer your question you will be limited to the people at your disposal. – Security Hound Jun 14 '12 at 13:38
  • Just wanted to thank everyone for the comments. I managed to fudge through a random message and found that the problem occurs when the message length is a multiple of 16. Did a quick search and turned this up: http://stackoverflow.com/questions/5884119/encrypting-16-bytes-of-utf8-with-seckeywrapper-breaks-ccstatus-4304. Problem now solved. Again, many thanks all. – Jonathan Smith Jun 14 '12 at 15:20

1 Answers1

1

Followed Ramhounds guidance and produced a different message of the same length. Problem is down to the encryption library on the iOS.

Found the answer here: Encrypting 16 bytes of UTF8 with SecKeyWrapper breaks (ccStatus == -4304)

Community
  • 1
  • 1
Jonathan Smith
  • 2,390
  • 1
  • 34
  • 60