» Fig Leaf Software Home

We've Got You Covered.

Friday, July 12, 2013

Google Maps API for Business: Generating Valid Signatures with Adobe ColdFusion 9 or 10

If you're contemplating using the Google Maps API for Business for your next mobile or desktop applications,  you will need to generate a valid digital signature from the private crypto key that Google provides, that needs to be passed as a URL parameter along with the Client ID (provided by Google) for your organization to invoke some of the enhanced web services.  

Google Developers' YouTube channel has a video with step-by-step instructions on how to generate a valid signature from your customer key using Python.

Detailed explanations on the 5 steps you must follow to generate a valid digital signature are documented on Google Developer site with examples in Python, C#, Java, etc., but not in Adobe ColdFusion: http://goo.gl/iYLPi

I recently had to help a fellow Senior Developer with generating a valid digital signature using Adobe ColdFusion 9 to fetch a street view image associated with a coordinate point, and you can check out the steps involved and corresponding ColdFusion code snippet from my Google/Android Blogspot below. 

Note: You can easily convert this snippet into a User-defined Function that accepts the coordinates as the input parameters and returns the digital signature in modified Binary64, that is safe to be passed as a URL parameter.  Please make use of the function HMAC() that is available in Adobe ColdFusion 10 instead, if you're coding in ColdFusion 10: http://goo.gl/O1e2W


//Step 1: Construct full URL to retrieve street view image.
google_mapapi_url = "http://maps.googleapis.com";
streetviewimage_endpoint = "/maps/api/streetview";
encodedParameters = 
  = google_mapapi_url & streetviewimage_endpoint & "?" &encodedParameters;
//Step 2: Strip off the domain portion of the full URL.     
url_to_sign = streetviewimage_endpoint & "?" & encodedParameters;

//Step 3.1: Retrieve your private key.
//Step 3.2: Decode the private key from web-safe base 64 to binary.
   = Replace(Replace(privatekey,"-","+","all"),"_","/","all"); 
decodedKeyBinary = BinaryDecode(privatekeyBase64,"base64");

//Step 3.3: Sign the URL in Step 2 above using the HMAC-SHA1 algorithm.
// Get an HMAC-SHA1 signing key from the raw key bytes.
secretKeySpec = 
//Note: In ColdFusion 10, you can simply use HMAC() function.
 = CreateObject("java","javax.crypto.Mac").getInstance("HmacSHA1");


// Compute the binary signature for the request.     
encryptedBytes = Hmac.doFinal(toBinary(toBase64(url_to_sign)));

// Encode the binary signature in base 64.
signature = BinaryEncode(encryptedBytes, "base64");

//Step 4: Convert the signature into something that can be passed within a URL.
signatureModified = Replace(Replace(signature,"+","-","all"),"/","_","all");

//Step 5: Attach the signature to the URL parameter signature
streetimage_url =  full_url & "&signature=" & signatureModified;


No comments:

Post a Comment

About Us

Fig Leaf Software is an award-winning team of imaginative designers, innovative developers, experienced instructors, and insightful strategists.

For over 20 years, we’ve helped a diverse range of clients...

Read More

Contact Us


Fig Leaf Software

1400 16th Street NW
Suite 450
Washington, DC 20036