Skip to content

Instantly share code, notes, and snippets.

View GArrigotti's full-sized avatar

Greg Arrigotti GArrigotti

  • Arrigotti Consulting
  • Portland, Oregon
View GitHub Profile

Keybase proof

I hereby claim:

  • I am garrigotti on github.
  • I am garrigotti (https://keybase.io/garrigotti) on keybase.
  • I have a public key ASAMVlNoKXAuKMWCXN3gZmyxLBF0hqVcfSEV-Z8RfgPY8go

To claim this, I am signing this object:

@GArrigotti
GArrigotti / Keybase.md
Created June 12, 2020 02:40
Keybase.md

Keybase proof

I hereby claim:

  • I am garrigotti on github.
  • I am garrigotti (https://keybase.io/garrigotti) on keybase.
  • I have a public key ASA3FHJoOkvt3AGaarjnFsf-fZ98raEgS0WPInQwSxgbAAo

To claim this, I am signing this object:

public TokenRecord GenerateToken(string url, string user, string key)
{
var expiration = (long)DateTime.UtcNow.AddMinutes(30).Subtract(DateTime.UnixEpoch).TotalSeconds;
var endpoint = HttpUtility.UrlEncode(url);
using var hash = new HMACSHA256(Encoding.UTF8.GetBytes(key));
var signature = HttpUtility.UrlEncode(Convert.ToBase64String(hash.ComputeHash(Encoding.UTF8.GetBytes($"{endpoint}\n{expiration}"))));
hash.Dispose();
return new TokenRecord($"SharedAccessSignature sr={endpoint}&sig={signature}&se={expiration}&skn={user}", DateTime.UnixEpoch.AddSeconds(expiration));