properly dispose of cryptography-related classes.

This commit is contained in:
morkt 2016-02-18 02:36:03 +04:00
parent 747f917b44
commit 3e313995d7
2 changed files with 9 additions and 7 deletions

View File

@ -125,11 +125,12 @@ namespace GameRes.Formats.Purple
if (index.Length != index_size)
return null;
var md5 = MD5.Create();
var hash = md5.ComputeHash (index);
if (!header.Skip (0x10).Take (0x10).SequenceEqual (hash))
return null;
using (var md5 = MD5.Create())
{
var hash = md5.ComputeHash (index);
if (!header.Skip (0x10).Take (0x10).SequenceEqual (hash))
return null;
}
foreach (var scheme in KnownSchemes.Values)
{
// both CmvsMd5 and index will be altered by ReadIndex in decryption attempt

View File

@ -89,8 +89,9 @@ namespace GameRes.Formats.NScripter
for (int i = 0; i < 16; i++)
hmac_key[i] = (byte)(md5_hash[i] ^ sha1_hash[i]);
var HMAC = new HMACSHA512 (hmac_key);
var hmac_hash = HMAC.ComputeHash (m_key);
byte[] hmac_hash;
using (var HMAC = new HMACSHA512 (hmac_key))
hmac_hash = HMAC.ComputeHash (m_key);
int[] map = Enumerable.Range (0, 256).ToArray();