mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-18 23:48:35 +02:00
ef3777fccf
Include NzbDrone.Update in mono/osx package Do not ignore certificate warnings for services Check hash before extracting update New: Update support for Linux/OS X - see the wiki for more information
39 lines
935 B
C#
39 lines
935 B
C#
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace NzbDrone.Core
|
|
{
|
|
public static class Security
|
|
{
|
|
public static string SHA256Hash(this string input)
|
|
{
|
|
using (var hash = SHA256Managed.Create())
|
|
{
|
|
var enc = Encoding.UTF8;
|
|
return GetHash(hash.ComputeHash(enc.GetBytes(input)));
|
|
}
|
|
}
|
|
|
|
public static string SHA256Hash(this Stream input)
|
|
{
|
|
using (var hash = SHA256Managed.Create())
|
|
{
|
|
return GetHash(hash.ComputeHash(input));
|
|
}
|
|
}
|
|
|
|
private static string GetHash(byte[] bytes)
|
|
{
|
|
var stringBuilder = new StringBuilder();
|
|
|
|
foreach (var b in bytes)
|
|
{
|
|
stringBuilder.Append(b.ToString("x2"));
|
|
}
|
|
|
|
return stringBuilder.ToString();
|
|
}
|
|
}
|
|
}
|