I want to create an iOS mobile application which is to communicate with my Node.js web application. To encrypt the data being sent from the mobile device to the web application, I've decided to use AES 256 encryption and then converting to base64. The problem is that all the Objective-C libraries that I found do not have the same output (for the same password and input text) as the Node.js ones. I don't know what to do...
Here are some of the iOS libraries:
- FBEncryptor
- AESCrypt
- also here is quite a nice example
Also, for the Node.js platform I tried these libraries:
- all these four libraries
based on this example I've constructed mine:
var crypto = require('crypto'); var key = "onceuponatime"; var toCrypt = "Hello World!"; var output = ''; var decrypted = ''; var cipher = crypto.createCipher('aes256', key); output += cipher.update(toCrypt, 'utf-8', 'base64'); output += cipher.final('base64'); console.log(output); var deCipher = crypto.createDecipher('aes256', key); decrypted += deCipher.update(output,'base64','utf-8'); decrypted += deCipher.final('utf-8'); console.log(decrypted);
Using FBEncryptor
and my Node.js
example I get the following encrypted base64 strings for the input I've provided: 7TsBLBvS6A1iByn9OTkzWA==
and mZ9cf4oklVN2ZnD0oQ0Tjw==
. Could you help me find a solution where I would get the same encrypted string both on iOS and on Node.js? Thanks.