mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Add helpers for quickly generating unique IDs
This commit is contained in:
@@ -3,6 +3,8 @@ using System.IO;
|
||||
using System.Threading;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Zune;
|
||||
|
||||
@@ -24,4 +26,28 @@ internal static class Extensions
|
||||
return client.GetStreamAsync(uri);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static int HashToInt32(this string id)
|
||||
{
|
||||
var hashBytes = id.Hash();
|
||||
return BitConverter.ToInt32(hashBytes, 0) ^ BitConverter.ToInt32(hashBytes, 4);
|
||||
}
|
||||
|
||||
public static Guid HashToGuid(this string id)
|
||||
{
|
||||
var hashBytes = id.Hash();
|
||||
return new Guid(hashBytes);
|
||||
}
|
||||
|
||||
public static long HashToInt64(this string id)
|
||||
{
|
||||
var hashBytes = id.Hash();
|
||||
return BitConverter.ToInt64(hashBytes, 0);
|
||||
}
|
||||
|
||||
public static byte[] Hash(this string id)
|
||||
{
|
||||
MD5 md5 = MD5.Create();
|
||||
return md5.ComputeHash(Encoding.Default.GetBytes(id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user