Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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

PREVIOUS NEXT
Code Example
Csharp :: how to check to see if the keyboard buttons are pressed in unity 
Csharp :: ef core many to many fluent api 
Csharp :: c# datagridview change column alignment 
Csharp :: unity save scene at runtime 
Csharp :: convert list of string to dictionary 
Csharp :: c# convert list to string and back 
Csharp :: linq c# where condition 
Csharp :: elasticsearch nested aggregation in c# 
Csharp :: C# Convert xml to datatable 
Csharp :: c# interface property 
Csharp :: dbset properties 
Csharp :: ontriggerenter unity not working 
Csharp :: c# reflection create generic type 
Csharp :: math.pow in C# using loop 
Csharp :: linq where condition c# 
Csharp :: what is int.parse in c# 
Csharp :: calculate string length vs pixels c# 
Csharp :: unity image button 
Csharp :: c# button click gets assigned the last value 
Csharp :: c# convert string to base64 string 
Csharp :: c# different getter setter types 
Csharp :: List of border roleplays roblox 
Csharp :: unity set dictionary value 
Csharp :: close an open form when you open it again c# 
Csharp :: cannot convert from group method to threadstart C# 
Csharp :: C# milisecond to h m s 
Csharp :: c sharp right rotation 
Csharp :: jtoken null or exists c# 
Csharp :: text mesh pro 
Csharp :: delete content from file c# 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =