gzkda.blogg.se

Download random password generator aes 256
Download random password generator aes 256





That defeats the purpose of the password. The attacker can know the Salt and IV, you can even use the Salt to generate the IV (or initialize the RNG for it), but you cannot use the password to generate either. (Or in the case of ASP.NET Entity Framework / Simple Membership this is all stored in one column with separators.) Many time, in the case of a database, it will have two (or three) columns: EncryptedPassword and Salt (maybe IV if it's not based on the Salt). The salt should be random and if two users with the exact same password have the same salt, well now either of them can attack the other. Generating the saltBytes based on the password is a bad idea. Dead code is dead.Īs stated in the comments: byte saltBytes = SHA512.Create().ComputeHash(passwordBytes) There are three magic numbers in here: AES.KeySize = 256 Īlso, that comment should go.

download random password generator aes 256

Private static byte removeTagAndIV(byte arr)īyte enc = new byte Īrray.Copy(arr, IV_LENGTH, enc, 0, arr.Length - IV_LENGTH)

download random password generator aes 256

Using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))Ĭs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length) Using (MemoryStream ms = new MemoryStream())īytesToBeDecrypted = removeTagAndIV(bytesToBeDecrypted) Using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())ĭecryption code : public static byte AES_Decrypt(byte bytesToBeDecrypted, byte passwordBytes) Using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))Ĭs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length) ĮncryptedBytesAndIV = new byte ĮncryptedBytes.CopyTo(encryptedBytesAndIV, IV_LENGTH) Var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 100) Using (AesCryptoServiceProvider AES = new AesCryptoServiceProvider()) Using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) Public static byte AES_Encrypt(byte bytesToBeEncrypted, byte passwordBytes)īyte saltBytes = SHA512.Create().ComputeHash(passwordBytes) the result is both have different data, and decrypt succeed.Īlso made test before the random IV, both files had same encrypted text, results in same data.Įncryption code : private static int IV_LENGTH = 16 The Code bellow is working, I've made a test to encrypt 2 text files with exact same text inside each.

download random password generator aes 256

( IV length 16 is added to the encrypted file, removed from file before decryption)ĭo you see any flows, something that needs optimization ?

download random password generator aes 256

  • saltBytes is now the SHA512 of the password.
  • I've made some improvments on the code from : Csharp-AES-bits-Encryption-Library-with-Salt







    Download random password generator aes 256