Archive for November, 2011

Using CryptAcquireContext ASP.NET Web Service

November 16, 2011

Hey. I’ve been signing Google URLs via a Windows Service and everything been fine, thanks for asking.

To sign a Google API URLs (e.g. Google Directions API) you need a signing key and also a crypto library to use a HMAC – specifically HMACSHA1. So P/Invoking the Windows cryptographic API through .NET is fine until you need to do it through an ASP.NET Web Service. Anyway, I have seen many people trying to get this working without success and I thought I’d share my answer.

The main issue is when you call to “CryptAcquireContext”. If the calling user doesn’t have access, this method with return “File Not Found”, or something similar.

Simply make sure your web service runs in it’s own App Pool, and then change the Identity that the App Pool runs under.

In IIS7, right click the App Pool, Advanced Settings, In the list -> Process Model ->Identity. I changed this to “Local Service” and everything work fine after that. You can use “Network Service” but then this gives the process network access permissions.

Here is link on IIS7 and App Pool identities,