1

I am trying to get asymmetric encryption working in a program... I started out using code from the Apple documentation site (Certificate, Key, and Trust Services Programming Guide, section on Encrypting and Decrypting Data), with minor changes, when it was ready to run, decryption failed with error -9808.

After doing some searching, I discovered that some people have had that error and gotten it to go away by changing padding to kSecPaddingNone. After I did that, everything ran happily, but my decrypted data was garbage.

So I stared at the code for a while, couldn't find any obvious mistakes, then started searching the web for other solutions or ideas. I came across a thread on stackoverflow (RSA implementations in Objective C) and Parth Bhatt's code in the previous reply.

I imported his class into my program and ran the test, and, like some of the other people who commented on that thread, I also got garbage on the output, just like with the code I had written (that is, adapted from Apple's sample code).

So I am wondering if there may have been some change to the API that requires another call, or just what exactly is going on?

I did not seem to be able to comment on Parth's answer, which is why I am asking this new question.

Community
  • 1
  • 1
  • Reading that comment thread I don't see evidence, despite it being the accepted answer with several upvotes, that it works. It looks like the asker and answerer got together on skype later and fixed it but never updated the answer. Maybe you're better off sticking with Apple's sample project? You could perhaps edit this question to include relevant code, input, output, deviation from the expected output, and any suspicions / things you've ruled out from debugging so far, that would be a very good question. – Carl Veazey Mar 31 '13 at 06:19
  • I agree with Carl, this is an opportunity to create some record on stackoverflow to help others down the line with similar problems. Using `kSecPaddingNone` is fine for testing but I would use `kSecPaddingPKCS1` for real work as it will catch errors much earlier besides the security benefits – President James K. Polk Apr 01 '13 at 15:12

0 Answers0