Click here to Skip to main content
15,893,368 members
Articles / Web Development / ASP.NET

Transparent Cookie Encryption Via HTTP Module

Rate me:
Please Sign up or sign in to vote.
3.54/5 (7 votes)
5 Jul 2009CPOL4 min read 53.2K   384   23  
A C# HTTP module that encrypts and decrypts cookies transparently to an application
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
		<!--	COOKIE ENCRYPTION MODULE - Add this section to the web.config
			CookieEncryptionModule_CookieList
				This is a delimited list of cookie names
			CookieEncryptionModule_Separator
				This is a single character that is used to delimit cookie names in CookieEncryptionModule_CookieList
			CookieEncryptionModule_HandleOrIgnoreCookieList
				This determines whether CookieEncryptionModule_CookieList is inclusive or exclusive
					Handle - Only cookies in the list will be encrypted
					Ignore - Only cookies not in the list will be encrypted
			CookieEncryptionModule_UnencryptedCookiePolicy:
				This specifies how to handle expiration of unencrypted persistent cookies that are now identified as requiring encryption.
				Since only the the cookie name and value are sent in the request the expiration date/time must be reset to encrypt it.
					Ignore		- The cookie will not be encrypted unless it is reset by the application
					Clear		- The cookie will be deleted before the application sees it
								Note: This removes it from the request but not from the client
					Session		- The cookie will be converted to a session cookie
					Never		- Expiration set to 01/01/2099
					yy,dd,hh,mm,ss	- an expiration of yy years, dd days, hh hours, mm minutes and ss seconds will be set			
		-->
		<add key="CookieEncryptionModule_CookieList" value="TestCookie2"/>
		<add key="CookieEncryptionModule_Separator" value="|"/>
		<add key="CookieEncryptionModule_HandleOrIgnoreCookieList" value="Handle"/>
		<add key="CookieEncryptionModule_UnencryptedCookiePolicy" value="1,0,0,0,0"/>
  </appSettings>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions