Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# encrypted

string keyString = "encrypt123456789";
var key = Encoding.UTF8.GetBytes(keyString);//16 bit or 32 bit key string

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 :: C# short getter setter 
Csharp :: export list to excel c# 
Csharp :: quotes in string f# 
Csharp :: how to make player movement in unity 2d 
Csharp :: Write text in Word Document at specific location using C# 
Csharp :: create new object from generic c# 
Csharp :: unity tilemap get all tiles 
Csharp :: char array 
Csharp :: c# loop xml 
Csharp :: asp.net core identity get all roles 
Csharp :: set margin programmatically wpf c# 
Csharp :: unity c# cos inverse 
Csharp :: c# tostring decimal 2 places 
Csharp :: pyqt minimize to tray icon 
Csharp :: unity activate gameobject via script 
Csharp :: c# string right extension 
Csharp :: element click intercepted exception in selenium C# 
Csharp :: c# recursion formula for the factorial 
Csharp :: how to turn components on and off in unity through code 
Csharp :: mysql: [Warning] Using a password on the command line interface can be insecure. 
Csharp :: System.Data.Entity.Core.EntityException: The underlying provider failed on Open 
Csharp :: wpf keyboard press event 
Csharp :: unity unit tests 
Csharp :: how to change all values in dictionary c# 
Csharp :: ultimate space cruiser 
Csharp :: c# callback param 
Csharp :: c# array zaheln speichern 
Csharp :: nunit cleanup after all tests 
Csharp :: asp c# page scroll position change after postback 
Csharp :: save position unity 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =