Decrypt AES example for Android on iOS

I have an Android AES example for encryption / decription.

https://github.com/itog/CryptoSample/blob/master/src/com/pigmal/android/ex/crypto/Crypto.java#L35

I want to decrypt this on iOS. It looks almost impossible. I found this to make it easier, but failed:

https://github.com/Gurpartap/AESCrypt-ObjC

I don't even get a good answer from base64 decoding. Here is my code:

NSData *encryptedData = [NSData base64DataFromString:encrypted];
// returns null
NSData *decryptedData = [encryptedData decryptedAES128DataUsingKey:[[CRYPT_SEED dataUsingEncoding:NSUTF8StringEncoding] SHA256Hash] error:&error];
NSString* result = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding];
+4
source share
4 answers

First of all, AES is a symmetric cipher algorithm that should use the exact same key to encrypt messages, as well as to decrypt messages.

, , :

  • . Android- - getter setter AES, . AES Android iOS.
  • . Android, , AES-128, iOS, , AES-256
  • : iOS CBC, IV ( ) . / IV Android-.

, , . AES, , , , padding .

+2

:

  • . -, .

: https://www.eldos.com/sbb/platforms.php#product

Crypto ++ http://www.cryptopp.com

  • AES, AES Android iOS .

  • Base64, . Unicode (UTF16) iOS Unicode (UTF8) Android. , .

+2

, , .

, . - /, - . , .

, .

, , , , .

, , fairplay.

0

, , , - //. BASE64. Android , . Base64.NO_WRAP .

AESCrypt-ObjC IV Android/Java, , .

IV, iOS :

private static byte[] ivBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);

cipherText = cipher.doFinal(stuffIWantSafe.getBytes("UTF-8"));

String encodedCipherText = Base64.encodeToString(cipherText, Base64.NO_WRAP);

: IV , IV,

* : Android AESCrypt

0
source

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


All Articles