0

Currently we have Desktop application in which we have login screen for Authentication. We are using username and password for authentication, Although we have encrypted the pass with RijndaelManaged class with SALT key.

Code is mentioned below :

public String Encrypt(String plainText, String key)
        {
            var plainBytes = Encoding.UTF8.GetBytes(plainText);
            return Convert.ToBase64String(Encrypt(plainBytes, GetRijndaelManaged(key)));
        }

 public byte[] Encrypt(byte[] plainBytes, RijndaelManaged rijndaelManaged)
        {
            return rijndaelManaged.CreateEncryptor()
                .TransformFinalBlock(plainBytes, 0, plainBytes.Length);
        }

public RijndaelManaged GetRijndaelManaged(String secretKey)
        {
            var keyBytes = new byte[16];
            var secretKeyBytes = Encoding.UTF8.GetBytes(secretKey);
            Array.Copy(secretKeyBytes, keyBytes, Math.Min(keyBytes.Length, secretKeyBytes.Length));
            return new RijndaelManaged
            {
                Mode = CipherMode.CBC,
                Padding = PaddingMode.PKCS7,
                KeySize = 128,
                BlockSize = 128,
                Key = keyBytes,
                IV = keyBytes
            };
        }

While debugging this code, i understood that it is parallelly writing my credentials in System;s memory dump which we can access it through Task manager -> right click on process -> create dump file.

We although have solution to get new encryption algorithms involved. But currently we could not able to do that. Hence Please suggest how we can fix this issue? i do have tried similar code of RijndaelManaged with using statements for Cryptostream and Memorystream but it is giving me the same result. Although what i found is this code snippet impacting the same.

Please suggest. Thanks, Abhishek Nene

  • 1
    Your `secretKey` input is a string. That's an immutable, managed object: it can by copied around the heap by the GC (leaving multiple copies), and there's no way for you to clear it out of memory when you're done. If you need to protect data from a memory dump, you need to make sure that it only ever goes in memory which is ideally unmanaged (or at least pinned) so the GC doesn't make copies, and that it's mutable so that you can explicitly wipe it when you no longer need it. `SecureString` used to be the go-to solution here, but that's no longer recommended. Basically this is really hard. – canton7 Jun 12 '20 at 13:11
  • any other recommendations? – Abhishek Nene Jun 14 '20 at 13:31

0 Answers0