BUG - hot loading stack when loading collection of deprecated data
Dani_S
4,521
Reputation points
Hi,
Try to load 1000 items in debug mode of string of deprecated .
I'm using net 6,
Expected behavior: load without problem.
Actual: The VS 2022 stack.
Please fix.
Thanks,
/// <summary>
/// The class handle encript and decript string using AES
/// </summary>
public class AesHelper
{
private const string Key = "your key";// 128 bit key
private const string IV = "your iv";// 16 bytes IV
/// <summary>
/// Encripted the plain text
/// </summary>
/// <param name="plainText">The text to encript</param>
/// <returns>Returns encripted chipper text</returns>
public static string Encrypt(string plainText)
{
byte[] encrypted;
try
{
using (Aes myAes = Aes.Create())
{
myAes.IV = Convert.FromBase64String(IV);
myAes.Key = Convert.FromBase64String(Key);
encrypted = Encrypt(plainText, myAes.Key, myAes.IV);
}
return Convert.ToBase64String(encrypted);
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Decript the chipper text
/// </summary>
/// <param name="cipherText">The text to decript</param>
/// <returns>Returns decripted chipper text</returns>
public static string Decrypt(string cipherText)
{
try
{
using (Aes myAes = Aes.Create())
{
myAes.IV = Convert.FromBase64String(IV);
myAes.Key = Convert.FromBase64String(Key);
return Deprected(Convert.FromBase64String(cipherText), myAes.Key, myAes.IV);
}
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Encrypt the plian text
/// </summary>
/// <param name="plainText">The plian text to encrpt</param>
/// <param name="Key">The Key in bytes</param>
/// <param name="IV">The IV in bytes</param>
/// <returns>The encrypted plain text</returns>
/// <exception cref="ArgumentNullException">If argumants are null thow ArgumentNullException </exception>
private static byte[] Encrypt(string plainText, byte[] Key, byte[] IV)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException(nameof(plainText));
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
byte[] encrypted;
// Create an Aes object with the specified Key and IV.
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for encryption.
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
//Write all data to the stream.
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}
/// <summary>
/// Deprect the plian text
/// </summary>
/// <param name="cipherText">The chiper text to decrept</param>
/// <param name="Key">The Key in bytes</param>
/// <param name="IV">The IV in bytes</param>
/// <returns>The deprected chiper text</returns>
/// <exception cref="ArgumentNullException">If argumants are null thow ArgumentNullException </exception>
private static string Deprected(byte[] cipherText, byte[] Key, byte[] IV)
{
// Check arguments.
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("cipherText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
// Declare the string used to hold the decrypted text.
string plaintext = null;
// Create an Aes object with the specified Key and IV.
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for decryption.
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
plaintext = srDecrypt.ReadToEnd();
}
}
}
}
return plaintext;
}
}
Developer technologies | Visual Studio | Other
5,457 questions
Sign in to answer