From cce280d260420872dd354e657b0c2919a430b0b4 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Mon, 11 May 2015 16:06:31 -0700 Subject: [PATCH] HashAlgorithm.ComputerHash isn't thread safe, --- src/NzbDrone.Common/Crypto/HashConverter.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Common/Crypto/HashConverter.cs b/src/NzbDrone.Common/Crypto/HashConverter.cs index 3bd521f16..2645e2b09 100644 --- a/src/NzbDrone.Common/Crypto/HashConverter.cs +++ b/src/NzbDrone.Common/Crypto/HashConverter.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Security.Cryptography; using System.Text; @@ -8,12 +6,15 @@ namespace NzbDrone.Common.Crypto { public static class HashConverter { - private static SHA1 HashAlgorithm = SHA1.Create(); + private static readonly SHA1 Sha1 = SHA1.Create(); public static int GetHashInt31(string target) { - var hash = HashAlgorithm.ComputeHash(Encoding.Default.GetBytes(target)); - + byte[] hash; + lock (Sha1) + { + hash = Sha1.ComputeHash(Encoding.Default.GetBytes(target)); + } return BitConverter.ToInt32(hash, 0) & 0x7fffffff; } }