diff --git a/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs b/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs index 4f3849c8289..6d94840e8d1 100644 --- a/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs +++ b/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs @@ -25,13 +25,7 @@ public static void Main(string[] passwordargs) // string pwd1 = passwordargs[0]; // Create a byte array to hold the random value. - byte[] salt1 = new byte[8]; - using (RNGCryptoServiceProvider rngCsp = new -RNGCryptoServiceProvider()) - { - // Fill the array with a random value. - rngCsp.GetBytes(salt1); - } + byte[] salt1 = RandomNumberGenerator.GetBytes(8); //data1 can be a string or contents of a file. string data1 = "Some test data"; @@ -43,9 +37,8 @@ public static void Main(string[] passwordargs) try { // - Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1, -myIterations); - Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1); + Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1, myIterations, HashAlgorithmName.SHA256); + Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1, myIterations, HashAlgorithmName.SHA256); // // Encrypt the data. Aes encAlg = Aes.Create(); @@ -98,4 +91,4 @@ public static void Main(string[] passwordargs) } } } -// \ No newline at end of file +//