internal static UriQueryBuilder GetSignature(SharedAccessTablePolicy policy, string tableName, string accessPolicyIdentifier, string startPartitionKey, string startRowKey, string endPartitionKey, string endRowKey, string signature, string accountKeyName, string sasVersion, SharedAccessProtocol?protocols, IPAddressOrRange ipAddressOrRange) { CommonUtility.AssertNotNull("signature", signature); UriQueryBuilder uriQueryBuilder = new UriQueryBuilder(); AddEscapedIfNotNull(uriQueryBuilder, "sv", sasVersion); AddEscapedIfNotNull(uriQueryBuilder, "tn", tableName); AddEscapedIfNotNull(uriQueryBuilder, "spk", startPartitionKey); AddEscapedIfNotNull(uriQueryBuilder, "srk", startRowKey); AddEscapedIfNotNull(uriQueryBuilder, "epk", endPartitionKey); AddEscapedIfNotNull(uriQueryBuilder, "erk", endRowKey); AddEscapedIfNotNull(uriQueryBuilder, "si", accessPolicyIdentifier); AddEscapedIfNotNull(uriQueryBuilder, "sk", accountKeyName); AddEscapedIfNotNull(uriQueryBuilder, "sig", signature); AddEscapedIfNotNull(uriQueryBuilder, "spr", GetProtocolString(protocols)); AddEscapedIfNotNull(uriQueryBuilder, "sip", ipAddressOrRange?.ToString()); if (policy != null) { AddEscapedIfNotNull(uriQueryBuilder, "st", GetDateTimeOrNull(policy.SharedAccessStartTime)); AddEscapedIfNotNull(uriQueryBuilder, "se", GetDateTimeOrNull(policy.SharedAccessExpiryTime)); string value = SharedAccessTablePolicy.PermissionsToString(policy.Permissions); if (!string.IsNullOrEmpty(value)) { AddEscapedIfNotNull(uriQueryBuilder, "sp", value); } } return(uriQueryBuilder); }
internal static string GetHash(SharedAccessTablePolicy policy, string accessPolicyIdentifier, string startPartitionKey, string startRowKey, string endPartitionKey, string endRowKey, string resourceName, string sasVersion, SharedAccessProtocol?protocols, IPAddressOrRange ipAddressOrRange, string keyValue) { CommonUtility.AssertNotNullOrEmpty("resourceName", resourceName); CommonUtility.AssertNotNull("keyValue", keyValue); CommonUtility.AssertNotNullOrEmpty("sasVersion", sasVersion); string text = null; DateTimeOffset?value = null; DateTimeOffset?value2 = null; if (policy != null) { text = SharedAccessTablePolicy.PermissionsToString(policy.Permissions); value = policy.SharedAccessStartTime; value2 = policy.SharedAccessExpiryTime; } string text2 = string.Format(CultureInfo.InvariantCulture, "{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n{8}\n{9}\n{10}\n{11}", text, GetDateTimeOrEmpty(value), GetDateTimeOrEmpty(value2), resourceName, accessPolicyIdentifier, (ipAddressOrRange == null) ? string.Empty : ipAddressOrRange.ToString(), GetProtocolString(protocols), sasVersion, startPartitionKey, startRowKey, endPartitionKey, endRowKey); Logger.LogVerbose(null, "StringToSign = {0}.", text2); return(CryptoUtility.ComputeHmac256(keyValue, text2)); }
public string GetSharedAccessSignature(SharedAccessTablePolicy policy, string accessPolicyIdentifier, string startPartitionKey, string startRowKey, string endPartitionKey, string endRowKey, SharedAccessProtocol?protocols, IPAddressOrRange ipAddressOrRange) { if (!ServiceClient.Credentials.IsSharedKey) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Cannot create Shared Access Signature unless Account Key credentials are used.")); } string canonicalName = GetCanonicalName(); StorageCredentials credentials = ServiceClient.Credentials; string hash = SharedAccessSignatureHelper.GetHash(policy, accessPolicyIdentifier, startPartitionKey, startRowKey, endPartitionKey, endRowKey, canonicalName, "2018-03-28", protocols, ipAddressOrRange, credentials.Key); return(SharedAccessSignatureHelper.GetSignature(policy, Name, accessPolicyIdentifier, startPartitionKey, startRowKey, endPartitionKey, endRowKey, hash, credentials.KeyName, "2018-03-28", protocols, ipAddressOrRange).ToString()); }