/// <summary> /// Signs the request using premium subscription. /// </summary> /// <param name="uri"></param> /// <returns></returns> protected virtual Uri Sign(Uri uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (string.IsNullOrWhiteSpace(this.Key)) { throw new ArgumentException("Invalid signing key."); } if (this.ClientId == null) { throw new NullReferenceException("ClientID"); } if (!this.ClientId.StartsWith("gme-")) { throw new ArgumentException("A clientId must start with 'gme-'."); } var urlSegmentToSign = uri.LocalPath + uri.Query + "&client=" + this.ClientId; var privateKey = SignableRequest.FromBase64UrlString(this.Key); byte[] signature; using (var algorithm = new HMACSHA1(privateKey)) { signature = algorithm.ComputeHash(Encoding.ASCII.GetBytes(urlSegmentToSign)); } return(new Uri(uri.Scheme + "://" + uri.Host + urlSegmentToSign + "&signature=" + SignableRequest.ToBase64UrlString(signature))); }
internal Uri Sign(Uri _uri) { // Based on the C# sample from: https://developers.google.com/maps/documentation/business/webservices if (_uri == null) { throw new ArgumentNullException("_uri"); } if (this.ClientId == null) { throw new NullReferenceException("ClientID"); } if (string.IsNullOrWhiteSpace(this.SigningKey)) { throw new ArgumentException("Invalid signing key."); } if (!this.ClientId.StartsWith("gme-")) { throw new ArgumentException("A user ID must start with 'gme-'."); } var _urlSegmentToSign = _uri.LocalPath + _uri.Query + "&client=" + this.ClientId; var _privateKey = SignableRequest.FromBase64UrlString(SigningKey); byte[] _signature; using (var _algorithm = new HMACSHA1(_privateKey)) { _signature = _algorithm.ComputeHash(Encoding.ASCII.GetBytes(_urlSegmentToSign)); } return(new Uri(_uri.Scheme + "://" + _uri.Host + _urlSegmentToSign + "&signature=" + SignableRequest.ToBase64UrlString(_signature))); }