Question

I am encrypting files in C# using the RijndaelManaged class using the following code:

RijndaelManaged RMCrypto = new RijndaelManaged();

byte[] keyArray = UTF8Encoding.UTF8.GetBytes("**Random Passphrase**"); // 256-AES key             
RMCrypto.Key = keyArray;
RMCrypto.Mode = CipherMode.ECB;

FileStream fsCrypt = new FileStream(outputFile, FileMode.Create);

ICryptoTransform cTransform = RMCrypto.CreateEncryptor();
CryptoStream cs = new CryptoStream(fsCrypt, cTransform, CryptoStreamMode.Write);

FileStream fsIn = new FileStream(inputFile, FileMode.Open);

byte[] buffer = new byte[8 * 16384];
int len;
while ((len = fsIn.Read(buffer, 0, buffer.Length)) > 0)
{
    cs.Write(buffer, 0, len);
}

fsIn.Close();
cs.Close();
fsCrypt.Close();

How can I decrypt the same file in iOS Objective-C and use it?

Was it helpful?

Solution

You should be able to use the Apple supplied CommonCrypto functions. There are several answers here on SO with code and several 3rd party project such as RNCryptor that encapsulate CommonCrypto including availability via CocoaPods.

What is necessary is matching all the parameters such as key size (128/192/256), key, iv, data, mode and padding.

AES is a subset of Rijndael and generally there is no compatibility issue as long as the block size is 128 bits.

See my SO example code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top