简体   繁体   English

使用RijndaelManaged类在iOS Objective-C中解密文件

[英]Decrypt a file in iOS Objective-C encrypted using RijndaelManaged class

I am encrypting files in C# using the RijndaelManaged class using the following code: 我使用RijndaelManaged类通过以下代码在C#中加密文件:

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? 如何在iOS Objective-C中解密相同文件并使用它?

You should be able to use the Apple supplied CommonCrypto functions. 您应该能够使用Apple提供的CommonCrypto函数。 There are several answers here on SO with code and several 3rd party project such as RNCryptor that encapsulate CommonCrypto including availability via CocoaPods. 在SO上有一些代码答案,还有一些第三方项目,例如RNCryptor,它们封装了CommonCrypto,包括通过CocoaPods的可用性。

What is necessary is matching all the parameters such as key size (128/192/256), key, iv, data, mode and padding. 必须匹配所有参数,例如密钥大小(128/192/256),密钥,iv,数据,模式和填充。

AES is a subset of Rijndael and generally there is no compatibility issue as long as the block size is 128 bits. AES是Rijndael的子集,并且通常不存在兼容性问题,只要块大小为128位即可。

See my SO example code . 请参阅我的SO 示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM