


This is because System.Random is not a true random. However, System.Random is strongly not recommended to be used in cryptography. RNGCryptoServiceProvider.Create().GetBytes(ba) Īnother way of getting random bytes is by using System.Random. What I do is appending a random salt bytes in front of the original bytes before encryption, and remove it after decryption.Įxample of Appending Randomized Salt Before Encrypting a String What if we want the results different from each time it is encrypted?

string of "Hello World") for 10 times, the encrypted results will be the same. For those who is not familiar with base64 encoding, you may want to read Base What? A Practical Introduction to Base Encoding Getting Randomized Encryption Result with Salt You'll notice that the encrypted string is stored in base64 encoded mode. PasswordBytes = SHA256.Create().ComputeHash(passwordBytes) īyte bytesDecrypted = AES_Decrypt(bytesToBeDecrypted, passwordBytes) Public string DecryptText( string input, string password)īyte bytesToBeDecrypted = Convert.FromBase64String(input) īyte passwordBytes = (password)
