Horje
dotnet core encryption and decryption Code Example
dotnet core encryption and decryption
public static string EncryptString(string text, string keyString)
{
    var key = Encoding.UTF8.GetBytes(keyString);

    using (var aesAlg = Aes.Create())
    {
        using (var encryptor = aesAlg.CreateEncryptor(key, aesAlg.IV))
        {
            using (var msEncrypt = new MemoryStream())
            {
                using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                using (var swEncrypt = new StreamWriter(csEncrypt))
                {
                    swEncrypt.Write(text);
                }

                var iv = aesAlg.IV;

                var decryptedContent = msEncrypt.ToArray();

                var result = new byte[iv.Length + decryptedContent.Length];

                Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
                Buffer.BlockCopy(decryptedContent, 0, result, iv.Length, decryptedContent.Length);

                return Convert.ToBase64String(result);
            }
        }
    }
}




Csharp

Related
DotNet web Api Token based Authentication Code Example DotNet web Api Token based Authentication Code Example
textbox gotfocus wpf Code Example textbox gotfocus wpf Code Example
mvc dotnet core how does the view pass parameters to controler Code Example mvc dotnet core how does the view pass parameters to controler Code Example
How to execute a script after the c# function executed Code Example How to execute a script after the c# function executed Code Example
run a command line from vb.net app Code Example run a command line from vb.net app Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12