mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 15:30:34 -04:00
* Ensure that after we assign a role to a user, we show it immediately * Cached libraryType api as that is not going to change in a viewing session. Moved some components around to tighten bundles. * Cleaned up more TODOs * Refactored Configuration to use getter and setters so that the interface is a lot cleaner. Updated HashUtil to use JWT Secret instead of Machine name (as docker machine name is random each boot).
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace Kavita.Common
|
|
{
|
|
public static class HashUtil
|
|
{
|
|
private static string CalculateCrc(string input)
|
|
{
|
|
uint mCrc = 0xffffffff;
|
|
byte[] bytes = Encoding.UTF8.GetBytes(input);
|
|
foreach (byte 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);
|
|
}
|
|
}
|
|
}
|