Added Dispose method

This commit is contained in:
Alexander 2018-12-28 12:58:07 +02:00
parent c257ef5a6e
commit 3a72117202
2 changed files with 9 additions and 4 deletions

View file

@ -28,7 +28,7 @@ public AESMetadata()
public void DeleteMetadataFromBuffer(ref byte[] rawData) public void DeleteMetadataFromBuffer(ref byte[] rawData)
{ {
byte[] buffer = new byte[rawData.Length - this.OffsetToData]; 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; rawData = buffer;
} }
@ -172,6 +172,7 @@ public static string Encrypt(string plainText, string password,
} }
symmetricKey.Dispose(); symmetricKey.Dispose();
derivedPassword.Dispose();
return Convert.ToBase64String(cipherTextBytes); return Convert.ToBase64String(cipherTextBytes);
} }
@ -240,6 +241,7 @@ public static string Decrypt(string cipherText, string password, string salt = "
symmetricKey.Dispose(); symmetricKey.Dispose();
} }
derivedPassword.Dispose();
return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount); return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount);
} }
} }

View file

@ -1,16 +1,19 @@
using System.Text; using System.Text;
using System.Security.Cryptography; using System.Security.Cryptography;
using System;
namespace Crypto_Notepad namespace Crypto_Notepad
{ {
/// <summary> /// <summary>
/// Stores a string encrypted in memory to defend against memory dumps /// Stores a string encrypted in memory to defend against memory dumps
/// </summary> /// </summary>
class EncryptedString class EncryptedString: IDisposable
{ {
private TripleDES des = TripleDESCryptoServiceProvider.Create(); private readonly TripleDES des = TripleDES.Create();
private byte[] encryptedString = null; private byte[] encryptedString = null;
public void Dispose() => des.Dispose();
public EncryptedString(string String) public EncryptedString(string String)
{ {
des.GenerateIV(); des.GenerateIV();