From 3e313995d7e0b28c8a1dfc5d8ab4d5c339821d5b Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 18 Feb 2016 02:36:03 +0400 Subject: [PATCH] properly dispose of cryptography-related classes. --- ArcFormats/Cmvs/ArcCPZ.cs | 11 ++++++----- ArcFormats/NScripter/EncryptedStream.cs | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ArcFormats/Cmvs/ArcCPZ.cs b/ArcFormats/Cmvs/ArcCPZ.cs index c8cddc12..0b05074b 100644 --- a/ArcFormats/Cmvs/ArcCPZ.cs +++ b/ArcFormats/Cmvs/ArcCPZ.cs @@ -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 diff --git a/ArcFormats/NScripter/EncryptedStream.cs b/ArcFormats/NScripter/EncryptedStream.cs index 85bc6883..8cd187b4 100644 --- a/ArcFormats/NScripter/EncryptedStream.cs +++ b/ArcFormats/NScripter/EncryptedStream.cs @@ -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();