0

This question might've already asked several times, but I honestly have yet to discover an answer that solved my problem.

Scenario: I have an encrypted file from server, probably using Java. The goal is to decrypt this file in iPhone (Objective-C).

I tried to decrypt using FBEncryptorAES to no avail.

Here's my decryption in Objective-C:

NSData *returnData = [FBEncryptorAES decryptData:stream key:key iv:nil];

The stream is encrypted NSData obtained from server, the key is the AES.

I have also written the equivalent Java code, and I could decrypt the data correctly using it and therefore verify that the key I'm using is identical byte-per-byte. Here's the said Java code:

SecretKeySpec key = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
cipherIn = new CipherInputStream(new FileInputStream(<decrypted-file>, cipher);

Any suggestion?

Thanks.

Rhama Arya Wibawa
  • 250
  • 1
  • 2
  • 15
  • 1
    I don't think that the language would matter in that case. http://stackoverflow.com/questions/9682118/objective-c-decrypt-aes-128-cbc-hex-string + this kind of question has been ask many times, search for it. – lc2817 Apr 05 '13 at 07:48
  • I'm sorry, accidentally hit the post button before completing my question. – Rhama Arya Wibawa Apr 05 '13 at 07:53
  • Have you checked that the format of the key is correct? Sometimes you need to convert it between implementations. Different cyphertext or key representations are usually the source of problems with inter-language encryption. – dtech Apr 05 '13 at 08:20
  • @dtech could you please be more specific about the key format? The Java code that I'm using to decrypt is ridiculously simple that I thought it shouldn't need more than default values with Objective-C. However, I tried `encodedKey = key.getEncoded()` from `SecretKeySpec` and printed its 16 bytes. It was identical with the `key` I'm giving to `FBEncryptorAES` to decrypt. – Rhama Arya Wibawa Apr 05 '13 at 08:45
  • 1
    I do not know, it is simply a possible reason for the problem. Try http://stackoverflow.com/questions/2280375/how-can-i-make-my-aes-encryption-identical-between-java-and-objective-c-iphone – dtech Apr 05 '13 at 11:32

0 Answers0