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)
|
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
var hash = GetHash(target);
|
|
|
|
|
return BitConverter.ToInt32(hash, 0) & 0x7fffffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] GetHash(string target)
|
|
|
|
|
{
|
2015-05-11 23:06:31 +00:00
|
|
|
|
lock (Sha1)
|
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
return Sha1.ComputeHash(Encoding.Default.GetBytes(target));
|
2015-05-11 23:06:31 +00:00
|
|
|
|
}
|
2014-12-26 13:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|