Created
November 2, 2011 18:33
-
-
Save PaulStovell/1334451 to your computer and use it in GitHub Desktop.
SHA512Managed is not thread safe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var hashAlgorithm = SHA512.Create(); | |
var text = "Hello world"; | |
var bytes = Encoding.Default.GetBytes(text); | |
var hashes = new List<string>(); | |
Parallel.For(0, 10000, ignored => | |
{ | |
var hashed = hashAlgorithm.ComputeHash(bytes); | |
var base64 = Convert.ToBase64String(hashed); | |
hashes.Add(base64); | |
}); | |
foreach (var hash in hashes) | |
{ | |
Console.WriteLine(hash); | |
} | |
Console.ReadKey(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pbackhuvud Yes, List is not thread-safe, but ComputeHash is not thread-safe too, that's the problem, I suppose.