Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API sample token generation code is wrong #28

Open
tmarkovski opened this issue Jul 23, 2019 · 0 comments
Open

Rest API sample token generation code is wrong #28

tmarkovski opened this issue Jul 23, 2019 · 0 comments

Comments

@tmarkovski
Copy link

Sample is outdated, the working code to generate the SAS token is

static private string CreateSharedAccessToken(string id, string key, DateTime then)
{
    // Important: seconds must be 0 for this to work
    DateTime expiry = new DateTime(then.Year, then.Month, then.Day, then.Hour, then.Minute, 0, DateTimeKind.Utc);
    using (HMACSHA512 hmac = new HMACSHA512(Encoding.UTF8.GetBytes(key)))
    {
        string dataToSign = id + "\n" + expiry.ToString("O", CultureInfo.InvariantCulture);
        byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(dataToSign));
        string signature = Convert.ToBase64String(hash);
        return $"{id}&{expiry:yyyyMMddHHmm}&{signature}";
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant