我使用以下代码使用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();
如何在iOS Objective-C中解密同一个文件并使用它?
答案 0 :(得分:1)
您应该可以使用Apple提供的CommonCrypto功能。这里有几个答案,包括代码和一些第三方项目,如RNCryptor,它封装了CommonCrypto,包括CocoaPods的可用性。
必要的是匹配所有参数,如密钥大小(128/192/256),密钥,iv,数据,模式和填充。
AES是Rijndael的子集,通常只要块大小为128位就没有兼容性问题。
查看我的SO example code。