Encryption on iOS5 and iOS4.3

The following code results in status = 0 in the iOS4.3 SDK on iOS4.3:

 size_t mySize, cypherSize; mySize = (secKeyGetBlockSize() - 11); // Code that reads in mySize bytes into buffer and // sets cipherSize to secKeyGetBlockSize(). // [...] status = SecKeyEncrypt(myPublicKey, kSecPaddingPKCS1, myBuffer, mySize, myBuffer, &cipherSize); 

It turns out that setKeyGetBlockSize() is 256 and therefore mySize = 245 . cypherSize always 256 after returning from SecKeyEncrypt .

In the iOS5 SDK running on iOS5, the same code is higher in status = -50 ! After some experimentation, I found that mySize = 244 (one lower than before!) Works again. I checked the SecKeyEncrypt documentation on iOS5.0 and it didn't change - so the size didn't change either.

What is the reason for this difference?

+4
source share
1 answer

I think your problem is cipherSize . You leave this variable uninitialized, but when you SecKeyEncrypt() it should contain the size of your myBuffer buffer (on the output it contains the number of bytes actually written to this buffer).

0
source

Source: https://habr.com/ru/post/1385010/


All Articles