Using CryptAcquireContext ASP.NET Web Service

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,

http://learn.iis.net/page.aspx/624/application-pool-identities/

Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: