Last active
September 4, 2019 01:15
-
-
Save AndrewSav/4363d01238213a66f3a7c8f5e8ec8a42 to your computer and use it in GitHub Desktop.
Calculates SteamGuard code from your base64 shared secret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string GetSteamGuardCode(string base64SharedSecret) | |
{ | |
long time = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + 10; | |
byte[] timeHash = BitConverter.GetBytes(time/30).Reverse().ToArray(); | |
HMACSHA1 hmac = new HMACSHA1(Convert.FromBase64String(base64SharedSecret)); | |
hmac.Initialize(); | |
byte[] hash = hmac.ComputeHash(timeHash); | |
int b = hash[19] & 0xF; | |
int codePoint = (hash[b] & 0x7F) << 24 | (hash[b + 1] & 0xFF) << 16 | (hash[b + 2] & 0xFF) << 8 | (hash[b + 3] & 0xFF); | |
string steamChars = "23456789BCDFGHJKMNPQRTVWXY"; | |
return new string(Enumerable.Range(0,5).Select(x => steamChars[codePoint/((int)Math.Pow(steamChars.Length,x)) % steamChars.Length]).ToArray()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment