0

I need to encrypt the data on iOS and Android and decrypt the data in Node using Crypto.

I'm trying to encrypt the data in Android and iOS and decrypt the same in NodeJs. The algorithm's, Key Length, Padding are not compatable on Android and iOS.

I'm using the following method in NodeJS to decrypt:

const algorithm = 'aes-128-ecb'; 
const appSecret = '1234567890123456';
decrypt(text) {
    var decipher = crypto.createDecipher(algorithm, appSecret);
    var dec = decipher.update(text, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

Android is using the same algorithm and appSecret and pkcs5 padding and are using MD5 to hash the key. I'm able to decrypt successfully when android encrypts the data. But I'm unable to decrypt the data coming from iOS after encryption even though they use the same algorithm and appSecret.

June7
  • 19,874
  • 8
  • 24
  • 34
  • Post the code you're using to encrypt the data on iOS. – David S. Jan 17 '18 at 17:25
  • 1
    I'd use Charles, Fiddler, or some other MITM attack to observe the raw data being passed back and forth. I had a similar issue where Android handled UTF8 encoding fine, but iOS garbled special characters like `&` and `+` and the only way I found the difference was by examining the raw payloads and comparing them to what they should be. Checkout my question at https://stackoverflow.com/questions/46762155/ios-urlsession-shared-datatask-removes-utf-8-character-and-replaces-it-with – James Jordan Taylor Jan 17 '18 at 17:27

1 Answers1

0
private secureKey = CryptoJS.enc.Base64.parse('123456789101234567890123456789011');
private secureIV = CryptoJS.enc.Base64.parse('1234567891123456');

var encrypted = CryptoJS.AES.decrypt(myText, this.secureKey, {
      iv: this.secureIV
    });
console.log('DecryptedData: '+encrypted);
Siundu254
  • 41
  • 4