Here’s a simple, 100% deterministic way to build a long, unique key from
• input.MatchId
• inputGames.Games[0].GameId
• inputGames.Games[0].Champ
and then SHA-512-hash it into a hex string.
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
// … inside your method …
// 1) Pull out the three “unique” fields
var matchId = input.MatchId;
var game0 = inputGames.Games[0];
var gameId = game0.GameId;
var champ = game0.Champ;
// 2) Concatenate with a stable delimiter
var rawKey = $"{matchId}|{gameId}|{champ}";
// 3) Compute SHA-512
string ComputeSHA512(string str)
{
using (var sha = SHA512.Create())
{
var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(str));
// turn each byte into two hex chars, e.g. "A3F4…"
return BitConverter
.ToString(bytes)
.Replace("-", "") // remove dashes
.ToLowerInvariant();
}
}
var uniqueHashKey = ComputeSHA512(rawKey);
Console.WriteLine($"rawKey: {rawKey}");
Console.WriteLine($"uniqueHashKey (SHA-512 hex): {uniqueHashKey}");
—
Explanation:
- Stable concatenation
You join your three values with a character (here “|”) that won’t appear in your data.
- Cryptographic hash
SHA-512 gives you a 128-character hex string with an astronomically small chance of collision.
- Deterministic
The same inputs ⇒ the same 128-char output.
If you really want a longer key (e.g. base-64), you can do:
string ComputeSHA512Base64(string str)
{
using (var sha = SHA512.Create())
{
var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(str));
return Convert.ToBase64String(bytes);
}
}
var longBase64Key = ComputeSHA512Base64(rawKey);
That will give you an 88-character string (instead of 128 hex chars).
Feel free to pick hex or Base64 depending on whether you need it URL-safe, human-readable, etc.