2014-12-26 13:55:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Crypto
|
|
|
|
|
{
|
|
|
|
|
public static class HashConverter
|
|
|
|
|
{
|
2015-05-11 23:06:31 +00:00
|
|
|
|
private static readonly SHA1 Sha1 = SHA1.Create();
|
2014-12-26 13:55:35 +00:00
|
|
|
|
|
|
|
|
|
public static int GetHashInt31(string target)
|
|
|
|
|
{
|
2015-05-11 23:06:31 +00:00
|
|
|
|
byte[] hash;
|
|
|
|
|
lock (Sha1)
|
|
|
|
|
{
|
|
|
|
|
hash = Sha1.ComputeHash(Encoding.Default.GetBytes(target));
|
|
|
|
|
}
|
2014-12-26 13:55:35 +00:00
|
|
|
|
return BitConverter.ToInt32(hash, 0) & 0x7fffffff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|