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)
{
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);
}
}

View file

@ -1,16 +1,19 @@
using System.Text;
using System.Security.Cryptography;
using System;
namespace Crypto_Notepad
{
/// <summary>
/// Stores a string encrypted in memory to defend against memory dumps
/// </summary>
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();