We have a requirement to create same encryption method for Android and iOS. We already have an existing working code written and Java but I am struggling to find the equivalent solution in Objective-C. Basically, this is what we want to replicate.
Cipher cipher = Cipher.getInstance("AES");
int blockSize = cipher.getBlockSize();
I am fairly new on encryptions so I might have stumbled useful article but cannot comprehend it fully.
Cipher
with algorithm "AES"
is using a provider specific mode of operation. For the normal JDK that means that it uses "AES/ECB/PKCS5Padding"
unless the providers have been messed with or a hardware key is used. Most providers will mimic the Oracle providers, so generally this is what you get.
So basically you need to implement AES in ECB mode (so without IV) and PKCS#7 padding (Java's PKCS#5 padding is not a correct name, but it is equivalent to PKCS#7 padding).
As for the block size: AES always has a block size of 128 bits. Rijndael, the original cipher may also have different block sizes, mainly 256 bits in addition to the 128 bits. So you have to be a bit more careful when specifying AES for a full implementation of Rijndael, and not confuse key sizes and block sizes.
Note that Cipher#getBlockSize()
returns the size in bytes rather than bits.
Note that ECB mode is generally not a secure way of applying a block cipher, so you may need to upgrade your protocol.