0
파일을 격리 저장소에 저장하고 파일을 열 때 복호화가 필요한 앱이 있습니다. IsolatedStorageFileStream을 바이트 배열에로드하고 AES256 암호 해독을 시작하려고했습니다. 파일 크기가 작 으면 제대로 작동합니다. 그러나 파일 크기가 크면 약 120MB로 System.OutOfMemoryException이 발생합니다. 다음은 내 코드의 일부입니다.Windows Phone 7에서 IsolatedStorageFileStream에서로드 할 때 System.OutOfMemoryException이 발생합니다.
IsolatedStorageFileStream m_rawStream =
IsolatedStorageFile.GetUserStoreForApplication().OpenFile("shared\\transfers\\" +
DownloadFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
byte[] m_rawByte = new byte[_totalByte];
m_rawStream.Read(m_rawByte, 0, _totalByte);
m_rawStream.Close();
//Decrypte downloaded epub
byte[] m_decryptedBytes = _decryptStringFromBytesAES(m_rawByte,
_hexStringToByteArray(_decryptKey),
_hexStringToByteArray(_decryptIV));
//Store on the upper layer of isolated storage
using (var isfs = new IsolatedStorageFileStream(DownloadFileName,
FileMode.Create,
IsolatedStorageFile.GetUserStoreForApplication()))
{
isfs.Write(m_decryptedBytes, 0, m_decryptedBytes.Length);
isfs.Flush();
}
//AES Decrypt helper
private byte[] _decryptStringFromBytesAES(byte[] cipherText, byte[] Key, byte[] IV)
{
// TDeclare the streams used
// to decrypt to an in memory
// array of bytes.
MemoryStream msDecrypt = null;
CryptoStream csDecrypt = null;
// Declare the RijndaelManaged object
// used to decrypt the data.
AesManaged aesAlg = null;
// Declare the byte[] used to hold
// the decrypted byte.
byte[] resultBytes = null;
try
{
// Create a RijndaelManaged object
// with the specified key and IV.
aesAlg = new AesManaged();
aesAlg.KeySize = 256;
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for decryption.
msDecrypt = new MemoryStream();
csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Write);
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
csDecrypt.Write(cipherText, 0, cipherText.Length);
//csDecrypt.FlushFinalBlock();
resultBytes = msDecrypt.ToArray();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
MessageBoxResult _result = MessageBox.Show("無法開啟檔案,請重試或聯絡技術人員。", "錯誤", MessageBoxButton.OK);
if (_result == MessageBoxResult.OK)
{
new SimpleNavigationService().Navigate("/View/MainPange.xaml");
}
}
return resultBytes;
}
OutOfMemory 예외가 발생하지 않도록하려면 어떻게해야합니까? 감사.
그 두 번째. 몇 년 전에 스트림에서 AES 암호 해독을 구현 했으므로이를 수행 할 수 있습니다. 나는 세부 사항을 더 이상 기억하지 않는다. –
BTW, Marketplace는 앱이 90MB 미만의 메모리를 사용하는지 테스트합니다. –