mirror of
https://github.com/ultrasn0w/app.git
synced 2025-12-13 12:29:53 +01:00
79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using APP.DTO;
|
|
|
|
namespace APP.Utility;
|
|
|
|
internal static class StringAssemble
|
|
{
|
|
private const string RegisterSecret = "綾波レイ";
|
|
|
|
internal static string UserInfo(User? user)
|
|
{
|
|
if (user == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var sb = new StringBuilder();
|
|
sb.Append("MAL ID:");
|
|
sb.AppendLine();
|
|
|
|
sb.Append("Last online:");
|
|
sb.AppendLine();
|
|
|
|
if (!string.IsNullOrEmpty(user.Location))
|
|
{
|
|
sb.Append("Location:");
|
|
sb.AppendLine();
|
|
}
|
|
|
|
sb.Append("Joined:");
|
|
sb.AppendLine();
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
internal static string UserData(User? user)
|
|
{
|
|
if (user == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var sb = new StringBuilder();
|
|
sb.Append(user.Id);
|
|
sb.AppendLine();
|
|
|
|
sb.Append(user.LastOnline);
|
|
sb.AppendLine();
|
|
|
|
if (!string.IsNullOrEmpty(user.Location))
|
|
{
|
|
sb.Append(user.Location);
|
|
sb.AppendLine();
|
|
}
|
|
|
|
sb.Append(user.Joined.ToShortDateString());
|
|
sb.AppendLine();
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
internal static string CalcSha512(string input)
|
|
{
|
|
var bytes = Encoding.UTF8.GetBytes(input);
|
|
using var hash = SHA512.Create();
|
|
var hashedInputBytes = hash.ComputeHash(bytes);
|
|
var hashedInputStringBuilder = new StringBuilder(128);
|
|
foreach (var b in hashedInputBytes)
|
|
hashedInputStringBuilder.Append(b.ToString("X2"));
|
|
return hashedInputStringBuilder.ToString().ToLower();
|
|
}
|
|
|
|
internal static string CalcSauce(long malId, string username)
|
|
{
|
|
return CalcSha512(RegisterSecret + malId + username);
|
|
}
|
|
}
|