Skip to content

Instantly share code, notes, and snippets.

@AndrewSav
Last active September 4, 2019 01:15
Show Gist options
  • Select an option

  • Save AndrewSav/4363d01238213a66f3a7c8f5e8ec8a42 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewSav/4363d01238213a66f3a7c8f5e8ec8a42 to your computer and use it in GitHub Desktop.

Revisions

  1. AndrewSav revised this gist Sep 4, 2019. No changes.
  2. AndrewSav revised this gist Sep 4, 2019. No changes.
  3. AndrewSav created this gist Jul 28, 2017.
    12 changes: 12 additions & 0 deletions GetSteamGuardCode.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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());
    }