Search code examples
phpxcodeencryptionswiftrncryptor

Encrypt in php and decrypt in swift


i'm coding an API in php to comunicate with an iOS App.

I would like to encrypt this data in php, transmit them and so decrypt in the iOS app (swift language)

To encrypt i php no problems:

$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);

But when i receive the data in iOS how can i decrypt them?

I saw RNCryptor that, of course, is written in objective-c and it could be integrated in a swift project, but when i add the files to the project x-code doesn't asks me if i want to integrate them and it doesn't make the bridging header.

Does someone have already had this problem or knows an alternative way to decrypt data in swift?


Solution

  • Just because Xcode didn't prompt you doesn't mean you can't make a bridging header. Just add a file to your project named "-Bridging-Header.h" (replace with your project's name, of course.

    Next look in build settings for the Objective-C Bridging Header field and set it to your header's name. Then you just import all the Objective-C headers you need in your bridging header.

    Make sure you add the bridging header in the root directory of your project. Xcode will probably try to add it in a subdirectory.