mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add option to consolidate duplicate ATA entities.
This commit is contained in:
36
DiscImageChef.Server/Core/Hash.cs
Normal file
36
DiscImageChef.Server/Core/Hash.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace DiscImageChef.Server
|
||||
{
|
||||
public static class Hash
|
||||
{
|
||||
public static string Sha512(byte[] data)
|
||||
{
|
||||
byte[] hash;
|
||||
|
||||
using(var sha = new SHA512Managed())
|
||||
{
|
||||
sha.Initialize();
|
||||
hash = sha.ComputeHash(data);
|
||||
}
|
||||
|
||||
char[] chars = new char[hash.Length * 2];
|
||||
|
||||
int j = 0;
|
||||
|
||||
foreach(byte b in hash)
|
||||
{
|
||||
int nibble1 = (b & 0xF0) >> 4;
|
||||
int nibble2 = b & 0x0F;
|
||||
|
||||
nibble1 += nibble1 > 9 ? 0x57 : 0x30;
|
||||
nibble2 += nibble2 > 9 ? 0x57 : 0x30;
|
||||
|
||||
chars[j++] = (char)nibble1;
|
||||
chars[j++] = (char)nibble2;
|
||||
}
|
||||
|
||||
return new string(chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user