From 3a721172021260cdb60ea4a15b2bc515e9868ae8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 28 Dec 2018 12:58:07 +0200 Subject: [PATCH] Added Dispose method --- Crypto Notepad/AES.cs | 6 ++++-- Crypto Notepad/EncryptedString.cs | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Crypto Notepad/AES.cs b/Crypto Notepad/AES.cs index 0d1fc27..6da4821 100644 --- a/Crypto Notepad/AES.cs +++ b/Crypto Notepad/AES.cs @@ -28,7 +28,7 @@ public AESMetadata() public void DeleteMetadataFromBuffer(ref byte[] rawData) { byte[] buffer = new byte[rawData.Length - this.OffsetToData]; - System.Buffer.BlockCopy(rawData, this.OffsetToData, buffer, 0, rawData.Length - this.OffsetToData); + Buffer.BlockCopy(rawData, this.OffsetToData, buffer, 0, rawData.Length - this.OffsetToData); rawData = buffer; } @@ -172,6 +172,7 @@ public static string Encrypt(string plainText, string password, } symmetricKey.Dispose(); + derivedPassword.Dispose(); return Convert.ToBase64String(cipherTextBytes); } @@ -239,7 +240,8 @@ public static string Decrypt(string cipherText, string password, string salt = " symmetricKey.Dispose(); } - + + derivedPassword.Dispose(); return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount); } } diff --git a/Crypto Notepad/EncryptedString.cs b/Crypto Notepad/EncryptedString.cs index c9dde26..701cd6b 100644 --- a/Crypto Notepad/EncryptedString.cs +++ b/Crypto Notepad/EncryptedString.cs @@ -1,16 +1,19 @@ using System.Text; using System.Security.Cryptography; +using System; namespace Crypto_Notepad { /// /// Stores a string encrypted in memory to defend against memory dumps /// - class EncryptedString + class EncryptedString: IDisposable { - private TripleDES des = TripleDESCryptoServiceProvider.Create(); + private readonly TripleDES des = TripleDES.Create(); private byte[] encryptedString = null; + public void Dispose() => des.Dispose(); + public EncryptedString(string String) { des.GenerateIV();