URL Signing?

13 views
Skip to first unread message

IanStallings

unread,
May 11, 2010, 10:34:03 AM5/11/10
to GeoCoding.Net
Hello GeoCoding.Net team,
Thanks for the code!

I've been using a basic URL signing class for Google's premier API. Do
you guys already have this or would you like to use this code? Can't
remember where I got this from to be honest, otherwise I'd credit the
original author. (No license in the code.)

public struct GoogleSignedUrl
{

public static string Sign(string url, string keyString)
{
ASCIIEncoding encoding = new ASCIIEncoding();

// converting key to bytes will throw an exception, need
to replace '-' and '_' characters first.
string usablePrivateKey = keyString.Replace("-",
"+").Replace("_", "/");
byte[] privateKeyBytes =
Convert.FromBase64String(usablePrivateKey);

Uri uri = new Uri(url);
byte[] encodedPathAndQueryBytes =
encoding.GetBytes(uri.LocalPath + uri.Query);

// compute the hash
HMACSHA1 algorithm = new HMACSHA1(privateKeyBytes);
byte[] hash =
algorithm.ComputeHash(encodedPathAndQueryBytes);

// convert the bytes to string and make url-safe by
replacing '+' and '/' characters
string signature =
Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_");

// Add the signature to the existing URI.
return url + "&signature=" + signature;
}
}

--
You received this message because you are subscribed to the Google Groups "GeoCoding.Net" group.
To post to this group, send email to geocod...@googlegroups.com.
To unsubscribe from this group, send email to geocodingnet...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/geocodingnet?hl=en.

IanStallings

unread,
May 11, 2010, 5:37:17 PM5/11/10
to GeoCoding.Net
When I dug in further I realized that the google geocoder class is
using V2 of the maps api, which does not require signing right now.
The Geocoding API V3 does and I've hacked the class to accommodate
this in a very ugly way so I doubt you'd like a patch. But if you want
I can write a better patch and submit it. Just wondering, is anyone
working on this already?

thanks,
Ian S

Chad Lee

unread,
May 12, 2010, 10:18:43 AM5/12/10
to geocod...@googlegroups.com
Hi Ian,

A patch would certainly be welcome.  I haven't read up on v3 of Google's API.  Are there any compelling reasons to upgrade to it?

Chad

Ian Stallings

unread,
May 12, 2010, 10:30:52 AM5/12/10
to geocod...@googlegroups.com
The main reason is to enable signing of requests, which is only used
by enterprise customers that want to go beyond the built-in limits.
For instance, we're working with a large data set of 1M+ addresses and
we go well over the 15k per day limit for the free geocoder so we
needed to use the enterprise features (non-free).

I can submit a patch; I'd like to build it in a way that defaults to
version 2, as it does now, but offer V3 support as an option. The XML
returned is different (not KML) so the parser would have to handle the
new version also. How about I work on it, submit it and have you look
over it? For most users the current one will be sufficient, this is
probably an edge case for usage.


- Ian S

Chad Lee

unread,
May 14, 2010, 9:59:48 AM5/14/10
to geocod...@googlegroups.com
Ian,

Sounds good - I look forward to your patch.

Chad
Reply all
Reply to author
Forward
0 new messages