I generated a random byte array of length 32 using SHA1PRNG in java, how can I get the same result in c#?
Java Code:
String seed = "Test";
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(seed.getBytes(StandardCharsets.UTF_8));
byte[] password = new byte[32];
random.nextBytes(password);
var encoder = java.util.Base64.getEncoder();
System.out.println(new String(encoder.encode(password), StandardCharsets.UTF_8));
I tried to use SHA1CryptoServiceProvider, but its HashSize is only 160(Length of 20)
C# Code:
string seed = "Test";
byte[] keyArray = new byte[32];
using (var sha1 = new SHA1CryptoServiceProvider())
{
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(seed));
var rd = sha1.ComputeHash(hash);
keyArray = rd.ToArray();
}
Console.WriteLine(Convert.ToBase64String(keyArray));