Kavita/Kavita.Common/HashUtil.cs
Joe Milazzo 9dc785f031
Epub Reading Overlay Re-Design (#2156)
* Removed DeviceId

* Dependency updates part 1

* Dependency updates part 2

* Dependency updates part 3

* Dependency updates part 4

* Dependency updates done. Updated all backend and UI ones.

* Refactored the book line overlay to sit at the top of the reader. It looks much better and will work a lot better for future work.

* Removed an event that was causing series detail to load extra data when it didn't need to after editing series metadata.

* Removed one more load request on series detail after updating edit series modal.
2023-07-23 13:35:16 -07:00

61 lines
1.5 KiB
C#

using System;
using System.Text;
namespace Kavita.Common;
public static class HashUtil
{
private static string CalculateCrc(string input)
{
var mCrc = 0xffffffff;
var bytes = Encoding.UTF8.GetBytes(input);
foreach (var myByte in bytes)
{
mCrc ^= (uint)myByte << 24;
for (var i = 0; i < 8; i++)
{
if ((Convert.ToUInt32(mCrc) & 0x80000000) == 0x80000000)
{
mCrc = (mCrc << 1) ^ 0x04C11DB7;
}
else
{
mCrc <<= 1;
}
}
}
return $"{mCrc:x8}";
}
/// <summary>
/// Calculates a unique, Anonymous Token that will represent this unique Kavita installation.
/// </summary>
/// <returns></returns>
public static string AnonymousToken()
{
var seed = $"{Environment.ProcessorCount}_{Environment.OSVersion.Platform}_{Configuration.JwtToken}_{Environment.UserName}";
return CalculateCrc(seed);
}
public static string ServerToken()
{
return AnonymousToken();
}
/// <summary>
/// Generates a unique API key to this server instance
/// </summary>
/// <returns></returns>
public static string ApiKey()
{
var id = Guid.NewGuid();
if (id.Equals(Guid.Empty))
{
id = Guid.NewGuid();
}
return id.ToString();
}
}