Hashes Generation Using .NET Core

I need to create random unique hashes that will be used in reset passwords in .Net Core. In ASP.NET Identity I found this useful, I wonder if RNGCryptoServiceProvider supports randomness of generated hashes.

using (RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider()) { var data = new byte[4]; for (int i = 0; i < 10; i++) { //filled with an array of random numbers rngCsp.GetBytes(data); //this is converted into a character from A to Z var randomchar = Convert.ToChar( //produce a random number //between 0 and 25 BitConverter.ToUInt32(data, 0) % 26 //Convert.ToInt32('A')==65 + 65 ); token.Append(randomchar); } } 

What is the best way to achieve this using the .net kernel and using which classes?

+5
source share
1 answer

RNGCryptoServiceProvider missing from .NET Core. Use RandomNumberGenerator.Create() to get an instance of CSPRNG that will run on the correct platform. Its API is the same as RNGCryptoServiceProvider , except that GetNonZeroBytes missing (which I would say was not even there).

On Windows, this will work before BCryptGenRandom on CNG, and on Linux it will use OpenSSL.

+8
source

Source: https://habr.com/ru/post/1258953/


All Articles