<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jaxley</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jaxley"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Jaxley"/>
		<updated>2026-05-15T16:18:14Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175917</id>
		<title>Using the Java Cryptographic Extensions</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175917"/>
				<updated>2014-05-27T21:34:09Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: fixing imports&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Note:==&lt;br /&gt;
''The code included in this article has not been reviewed and should not be used without proper analysis.  If you have reviewed the included code (or portions of it), please post your findings back to this page or to: stephen [at] corsaire.com.''&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Java Cryptographic Extensions (JCE) is a set of Java API's which provides cryptographic services such as encryption, secret Key Generation, Message Authentication code and Key Agreement. The ciphers supported by JCE include symmetric, asymmetric, block and stream ciphers. JCE was an optional package to JDK v 1.2.x and 1.3.x. JCE has been integrated into JDK v1.4.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JCE API's are implemented by Cryptographic Service Providers. Each of these cryptographic service providers implements the Service Provider Interface which specifies the functionalities which needs to be implemented by the service providers. Programmers can plugin any Service Providers for performing cryptographic functionalities provided by JCE. J2SE comes with a default provider named SunJCE.&lt;br /&gt;
&lt;br /&gt;
===Symmetric Encryption Algorithms provided by SunJCE===&lt;br /&gt;
# DES  - default keylength of 56 bits&lt;br /&gt;
# AES - &lt;br /&gt;
# RC2, RC4 and RC5&lt;br /&gt;
# IDEA&lt;br /&gt;
# Triple DES – default keylength 112 bits&lt;br /&gt;
# Blowfish – default keylength 56 bits&lt;br /&gt;
# PBEWithMD5AndDES&lt;br /&gt;
# PBEWithHmacSHA1AndDESede&lt;br /&gt;
# DES ede&lt;br /&gt;
&lt;br /&gt;
===Modes of Encryption===&lt;br /&gt;
# ECB&lt;br /&gt;
# CBC&lt;br /&gt;
# CFB&lt;br /&gt;
# OFB&lt;br /&gt;
# PCBC&lt;br /&gt;
&lt;br /&gt;
===Asymmetric Encryption Algorithms implemented by SunJCE===&lt;br /&gt;
# RSA&lt;br /&gt;
# Diffie-Hellman – default keylength 1024 bits&lt;br /&gt;
&lt;br /&gt;
===Hashing / Message Digest Algorithms implemented by SunJCE===&lt;br /&gt;
# MD5 – default size 64 bytes&lt;br /&gt;
# SHA1 - default size 64 bytes&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===SecureRandom===&lt;br /&gt;
SecureRandom class is used to generate a cryptographically strong pseudo random number by using a PRNG Algorithm.&lt;br /&gt;
The following are the advantages of using SecureRandom over Random.&lt;br /&gt;
1. SecureRandom produces a cryptographically strong pseudo random number generator. &lt;br /&gt;
2. SecureRandom produces cryptographically strong sequences as described in &lt;br /&gt;
[http://www.ietf.org/rfc/rfc1750.txt RFC 1750: Randomness Recommendations for Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the functionality for Generating a Secure Random Number.&lt;br /&gt;
 *  &lt;br /&gt;
 * There are 2 ways to generate a  Random number through SecureRandom.&lt;br /&gt;
 * 1. By calling nextBytes method to generate Random Bytes&lt;br /&gt;
 * 2. Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class SecureRandomGen {&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * @param args&lt;br /&gt;
	 */&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
	        // Initialize a secure random number generator&lt;br /&gt;
	        SecureRandom secureRandom = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 1 - Calling nextBytes method to generate Random Bytes&lt;br /&gt;
	        byte[] bytes = new byte[512];&lt;br /&gt;
	        secureRandom.nextBytes(bytes); &lt;br /&gt;
	        &lt;br /&gt;
	        // Printing the SecureRandom number by calling secureRandom.nextDouble()&lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated by calling nextBytes() is &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 2 - Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
	        int seedByteCount = 10;&lt;br /&gt;
	        byte[] seed = secureRandom.generateSeed(seedByteCount);   &lt;br /&gt;
	        &lt;br /&gt;
	        // TBR System.out.println(&amp;quot; Seed value is &amp;quot; + new BASE64Encoder().encode(seed));&lt;br /&gt;
	    &lt;br /&gt;
	        secureRandom.setSeed(seed);&lt;br /&gt;
	        &lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated using setSeed(byte[]) is  &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	        &lt;br /&gt;
	    } catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== AES Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.spec.IvParameterSpec;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using AES&lt;br /&gt;
 * 2. Decryption using AES&lt;br /&gt;
 * &lt;br /&gt;
 * High Level Algorithm :&lt;br /&gt;
 * 1. Generate a AES key (specify the Key size during this phase) &lt;br /&gt;
 * 2. Create the Cipher &lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class AES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
&lt;br /&gt;
		try {&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 1. Generate an AES key using KeyGenerator Initialize the&lt;br /&gt;
			 * keysize to 128 bits (16 bytes)&lt;br /&gt;
			 * &lt;br /&gt;
			 */&lt;br /&gt;
			KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
			keyGen.init(128);&lt;br /&gt;
			SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 2. Generate an Initialization Vector (IV) &lt;br /&gt;
			 * 		a. Use SecureRandom to generate random bits&lt;br /&gt;
			 * 		   The size of the IV matches the blocksize of the cipher (128 bits for AES)&lt;br /&gt;
			 * 		b. Construct the appropriate IvParameterSpec object for the data to pass to Cipher's init() method&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			final int AES_KEYLENGTH = 128;	// change this as desired for the security level you want&lt;br /&gt;
			byte[] iv = new byte[AES_KEYLENGTH / 8];	// Save the IV bytes or send it in plaintext with the encrypted data so you can decrypt the data later&lt;br /&gt;
			SecureRandom prng = new SecureRandom();&lt;br /&gt;
			prng.nextBytes(iv);&lt;br /&gt;
			&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 3. Create a Cipher by specifying the following parameters&lt;br /&gt;
			 * 		a. Algorithm name - here it is AES &lt;br /&gt;
			 * 		b. Mode - here it is CBC mode &lt;br /&gt;
			 * 		c. Padding - e.g. PKCS7 or PKCS5&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			Cipher aesCipherForEncryption = Cipher.getInstance(&amp;quot;AES/CBC/PKCS7PADDING&amp;quot;); // Must specify the mode explicitly as most JCE providers default to ECB mode!!&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 4. Initialize the Cipher for Encryption&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			aesCipherForEncryption.init(Cipher.ENCRYPT_MODE, secretKey, &lt;br /&gt;
					new IvParameterSpec(iv));&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 5. Encrypt the Data &lt;br /&gt;
			 * 		a. Declare / Initialize the Data. Here the data is of type String &lt;br /&gt;
			 * 		b. Convert the Input Text to Bytes &lt;br /&gt;
			 * 		c. Encrypt the bytes using doFinal method&lt;br /&gt;
			 */&lt;br /&gt;
			strDataToEncrypt = &amp;quot;Hello World of Encryption using AES &amp;quot;;&lt;br /&gt;
			byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
			byte[] byteCipherText = aesCipherForEncryption&lt;br /&gt;
					.doFinal(byteDataToEncrypt);&lt;br /&gt;
			// b64 is done differently on Android&lt;br /&gt;
			strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
			System.out.println(&amp;quot;Cipher Text generated using AES is &amp;quot;&lt;br /&gt;
					+ strCipherText);&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 6. Decrypt the Data &lt;br /&gt;
			 * 		a. Initialize a new instance of Cipher for Decryption (normally don't reuse the same object)&lt;br /&gt;
			 * 		   Be sure to obtain the same IV bytes for CBC mode.&lt;br /&gt;
			 * 		b. Decrypt the cipher bytes using doFinal method&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			Cipher aesCipherForDecryption = Cipher.getInstance(&amp;quot;AES/CBC/PKCS7PADDING&amp;quot;); // Must specify the mode explicitly as most JCE providers default to ECB mode!!				&lt;br /&gt;
&lt;br /&gt;
			aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey,&lt;br /&gt;
					new IvParameterSpec(iv));&lt;br /&gt;
			byte[] byteDecryptedText = aesCipherForDecryption&lt;br /&gt;
					.doFinal(byteCipherText);&lt;br /&gt;
			strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
			System.out&lt;br /&gt;
					.println(&amp;quot; Decrypted Text message is &amp;quot; + strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo) {&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (NoSuchPaddingException noSuchPad) {&lt;br /&gt;
			System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (InvalidKeyException invalidKey) {&lt;br /&gt;
			System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (BadPaddingException badPadding) {&lt;br /&gt;
			System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (IllegalBlockSizeException illegalBlockSize) {&lt;br /&gt;
			System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (InvalidAlgorithmParameterException invalidParam) {&lt;br /&gt;
			System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Des Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.crypto;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using DES&lt;br /&gt;
 * 2. Decryption using DES&lt;br /&gt;
 * &lt;br /&gt;
 * The following modes of DES encryption are supported by SUNJce provider &lt;br /&gt;
 * 1. ECB (Electronic code Book) - Every plaintext block is encrypted separately &lt;br /&gt;
 * 2. CBC (Cipher Block Chaining) - Every plaintext block is XORed with the previous ciphertext block&lt;br /&gt;
 * 3. PCBC (Propogating Cipher Block Chaining) - &lt;br /&gt;
 * 4. CFB (Cipher Feedback Mode) - The previous ciphertext block is encrypted and this enciphered block is XORed with the plaintext block to produce the corresponding ciphertext block &lt;br /&gt;
 * 5. OFB (Output Feedback Mode) - &lt;br /&gt;
 *&lt;br /&gt;
 *	High Level Algorithm :&lt;br /&gt;
 * 1. Generate a DES key&lt;br /&gt;
 * 2. Create the Cipher (Specify the Mode and Padding)&lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * Need for Padding :&lt;br /&gt;
 * Block ciphers operates on data blocks on fixed size n. &lt;br /&gt;
 * Since the data to be encrypted might not always be a multiple of n, the remainder of the bits are padded.&lt;br /&gt;
 * PKCS#5 Padding is what will be used in this program &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class DES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
		&lt;br /&gt;
		try{&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 1. Generate a DES key using KeyGenerator &lt;br /&gt;
		 * &lt;br /&gt;
		 */&lt;br /&gt;
		KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;DES&amp;quot;);&lt;br /&gt;
		SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step2. Create a Cipher by specifying the following parameters&lt;br /&gt;
		 * 			a. Algorithm name - here it is DES&lt;br /&gt;
		 * 			b. Mode - here it is CBC&lt;br /&gt;
		 * 			c. Padding - PKCS5Padding&lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		Cipher desCipher = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;); /* Must specify the mode explicitly as most JCE providers default to ECB mode!! */&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 3. Initialize the Cipher for Encryption &lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		desCipher.init(Cipher.ENCRYPT_MODE,secretKey);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 4. Encrypt the Data&lt;br /&gt;
		 *  		1. Declare / Initialize the Data. Here the data is of type String&lt;br /&gt;
		 *  		2. Convert the Input Text to Bytes&lt;br /&gt;
		 *  		3. Encrypt the bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		strDataToEncrypt = &amp;quot;Hello World of Encryption using DES &amp;quot;;&lt;br /&gt;
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
		byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt); &lt;br /&gt;
		strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
		System.out.println(&amp;quot;Cipher Text generated using DES with CBC mode and PKCS5 Padding is &amp;quot; +strCipherText);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 5. Decrypt the Data&lt;br /&gt;
		 *  		1. Initialize the Cipher for Decryption &lt;br /&gt;
		 *  		2. Decrypt the cipher bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		desCipher.init(Cipher.DECRYPT_MODE,secretKey,desCipher.getParameters());&lt;br /&gt;
		 //desCipher.init(Cipher.DECRYPT_MODE,secretKey);&lt;br /&gt;
		byte[] byteDecryptedText = desCipher.doFinal(byteCipherText);&lt;br /&gt;
		strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
		System.out.println(&amp;quot; Decrypted Text message is &amp;quot; +strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
			catch (NoSuchPaddingException noSuchPad)&lt;br /&gt;
			{&lt;br /&gt;
				System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
				catch (InvalidKeyException invalidKey)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (BadPaddingException badPadding)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (IllegalBlockSizeException illegalBlockSize)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (InvalidAlgorithmParameterException invalidParam)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
				}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175916</id>
		<title>Using the Java Cryptographic Extensions</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175916"/>
				<updated>2014-05-27T21:29:35Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Note:==&lt;br /&gt;
''The code included in this article has not been reviewed and should not be used without proper analysis.  If you have reviewed the included code (or portions of it), please post your findings back to this page or to: stephen [at] corsaire.com.''&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Java Cryptographic Extensions (JCE) is a set of Java API's which provides cryptographic services such as encryption, secret Key Generation, Message Authentication code and Key Agreement. The ciphers supported by JCE include symmetric, asymmetric, block and stream ciphers. JCE was an optional package to JDK v 1.2.x and 1.3.x. JCE has been integrated into JDK v1.4.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JCE API's are implemented by Cryptographic Service Providers. Each of these cryptographic service providers implements the Service Provider Interface which specifies the functionalities which needs to be implemented by the service providers. Programmers can plugin any Service Providers for performing cryptographic functionalities provided by JCE. J2SE comes with a default provider named SunJCE.&lt;br /&gt;
&lt;br /&gt;
===Symmetric Encryption Algorithms provided by SunJCE===&lt;br /&gt;
# DES  - default keylength of 56 bits&lt;br /&gt;
# AES - &lt;br /&gt;
# RC2, RC4 and RC5&lt;br /&gt;
# IDEA&lt;br /&gt;
# Triple DES – default keylength 112 bits&lt;br /&gt;
# Blowfish – default keylength 56 bits&lt;br /&gt;
# PBEWithMD5AndDES&lt;br /&gt;
# PBEWithHmacSHA1AndDESede&lt;br /&gt;
# DES ede&lt;br /&gt;
&lt;br /&gt;
===Modes of Encryption===&lt;br /&gt;
# ECB&lt;br /&gt;
# CBC&lt;br /&gt;
# CFB&lt;br /&gt;
# OFB&lt;br /&gt;
# PCBC&lt;br /&gt;
&lt;br /&gt;
===Asymmetric Encryption Algorithms implemented by SunJCE===&lt;br /&gt;
# RSA&lt;br /&gt;
# Diffie-Hellman – default keylength 1024 bits&lt;br /&gt;
&lt;br /&gt;
===Hashing / Message Digest Algorithms implemented by SunJCE===&lt;br /&gt;
# MD5 – default size 64 bytes&lt;br /&gt;
# SHA1 - default size 64 bytes&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===SecureRandom===&lt;br /&gt;
SecureRandom class is used to generate a cryptographically strong pseudo random number by using a PRNG Algorithm.&lt;br /&gt;
The following are the advantages of using SecureRandom over Random.&lt;br /&gt;
1. SecureRandom produces a cryptographically strong pseudo random number generator. &lt;br /&gt;
2. SecureRandom produces cryptographically strong sequences as described in &lt;br /&gt;
[http://www.ietf.org/rfc/rfc1750.txt RFC 1750: Randomness Recommendations for Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the functionality for Generating a Secure Random Number.&lt;br /&gt;
 *  &lt;br /&gt;
 * There are 2 ways to generate a  Random number through SecureRandom.&lt;br /&gt;
 * 1. By calling nextBytes method to generate Random Bytes&lt;br /&gt;
 * 2. Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class SecureRandomGen {&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * @param args&lt;br /&gt;
	 */&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
	        // Initialize a secure random number generator&lt;br /&gt;
	        SecureRandom secureRandom = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 1 - Calling nextBytes method to generate Random Bytes&lt;br /&gt;
	        byte[] bytes = new byte[512];&lt;br /&gt;
	        secureRandom.nextBytes(bytes); &lt;br /&gt;
	        &lt;br /&gt;
	        // Printing the SecureRandom number by calling secureRandom.nextDouble()&lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated by calling nextBytes() is &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 2 - Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
	        int seedByteCount = 10;&lt;br /&gt;
	        byte[] seed = secureRandom.generateSeed(seedByteCount);   &lt;br /&gt;
	        &lt;br /&gt;
	        // TBR System.out.println(&amp;quot; Seed value is &amp;quot; + new BASE64Encoder().encode(seed));&lt;br /&gt;
	    &lt;br /&gt;
	        secureRandom.setSeed(seed);&lt;br /&gt;
	        &lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated using setSeed(byte[]) is  &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	        &lt;br /&gt;
	    } catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== AES Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using AES&lt;br /&gt;
 * 2. Decryption using AES&lt;br /&gt;
 * &lt;br /&gt;
 * High Level Algorithm :&lt;br /&gt;
 * 1. Generate a DES key (specify the Key size during this phase) &lt;br /&gt;
 * 2. Create the Cipher &lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class AES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
&lt;br /&gt;
		try {&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 1. Generate an AES key using KeyGenerator Initialize the&lt;br /&gt;
			 * keysize to 128 bits (16 bytes)&lt;br /&gt;
			 * &lt;br /&gt;
			 */&lt;br /&gt;
			KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
			keyGen.init(128);&lt;br /&gt;
			SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 2. Generate an Initialization Vector (IV) &lt;br /&gt;
			 * 		a. Use SecureRandom to generate random bits&lt;br /&gt;
			 * 		   The size of the IV matches the blocksize of the cipher (128 bits for AES)&lt;br /&gt;
			 * 		b. Construct the appropriate IvParameterSpec object for the data to pass to Cipher's init() method&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			final int AES_KEYLENGTH = 128;	// change this as desired for the security level you want&lt;br /&gt;
			byte[] iv = new byte[AES_KEYLENGTH / 8];	// Save the IV bytes or send it in plaintext with the encrypted data so you can decrypt the data later&lt;br /&gt;
			SecureRandom prng = new SecureRandom();&lt;br /&gt;
			prng.nextBytes(iv);&lt;br /&gt;
			&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 3. Create a Cipher by specifying the following parameters&lt;br /&gt;
			 * 		a. Algorithm name - here it is AES &lt;br /&gt;
			 * 		b. Mode - here it is CBC mode &lt;br /&gt;
			 * 		c. Padding - e.g. PKCS7 or PKCS5&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			Cipher aesCipherForEncryption = Cipher.getInstance(&amp;quot;AES/CBC/PKCS7PADDING&amp;quot;); // Must specify the mode explicitly as most JCE providers default to ECB mode!!&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 4. Initialize the Cipher for Encryption&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			aesCipherForEncryption.init(Cipher.ENCRYPT_MODE, secretKey, &lt;br /&gt;
					new IvParameterSpec(iv));&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 5. Encrypt the Data &lt;br /&gt;
			 * 		a. Declare / Initialize the Data. Here the data is of type String &lt;br /&gt;
			 * 		b. Convert the Input Text to Bytes &lt;br /&gt;
			 * 		c. Encrypt the bytes using doFinal method&lt;br /&gt;
			 */&lt;br /&gt;
			strDataToEncrypt = &amp;quot;Hello World of Encryption using AES &amp;quot;;&lt;br /&gt;
			byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
			byte[] byteCipherText = aesCipherForEncryption&lt;br /&gt;
					.doFinal(byteDataToEncrypt);&lt;br /&gt;
			// b64 is done differently on Android&lt;br /&gt;
			strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
			System.out.println(&amp;quot;Cipher Text generated using AES is &amp;quot;&lt;br /&gt;
					+ strCipherText);&lt;br /&gt;
&lt;br /&gt;
			/**&lt;br /&gt;
			 * Step 6. Decrypt the Data &lt;br /&gt;
			 * 		a. Initialize a new instance of Cipher for Decryption (normally don't reuse the same object)&lt;br /&gt;
			 * 		   Be sure to obtain the same IV bytes for CBC mode.&lt;br /&gt;
			 * 		b. Decrypt the cipher bytes using doFinal method&lt;br /&gt;
			 */&lt;br /&gt;
&lt;br /&gt;
			Cipher aesCipherForDecryption = Cipher.getInstance(&amp;quot;AES/CBC/PKCS7PADDING&amp;quot;); // Must specify the mode explicitly as most JCE providers default to ECB mode!!				&lt;br /&gt;
&lt;br /&gt;
			aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey,&lt;br /&gt;
					new IvParameterSpec(iv));&lt;br /&gt;
			byte[] byteDecryptedText = aesCipherForDecryption&lt;br /&gt;
					.doFinal(byteCipherText);&lt;br /&gt;
			strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
			System.out&lt;br /&gt;
					.println(&amp;quot; Decrypted Text message is &amp;quot; + strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo) {&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (NoSuchPaddingException noSuchPad) {&lt;br /&gt;
			System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (InvalidKeyException invalidKey) {&lt;br /&gt;
			System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (BadPaddingException badPadding) {&lt;br /&gt;
			System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (IllegalBlockSizeException illegalBlockSize) {&lt;br /&gt;
			System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		catch (InvalidAlgorithmParameterException invalidParam) {&lt;br /&gt;
			System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Des Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.crypto;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using DES&lt;br /&gt;
 * 2. Decryption using DES&lt;br /&gt;
 * &lt;br /&gt;
 * The following modes of DES encryption are supported by SUNJce provider &lt;br /&gt;
 * 1. ECB (Electronic code Book) - Every plaintext block is encrypted separately &lt;br /&gt;
 * 2. CBC (Cipher Block Chaining) - Every plaintext block is XORed with the previous ciphertext block&lt;br /&gt;
 * 3. PCBC (Propogating Cipher Block Chaining) - &lt;br /&gt;
 * 4. CFB (Cipher Feedback Mode) - The previous ciphertext block is encrypted and this enciphered block is XORed with the plaintext block to produce the corresponding ciphertext block &lt;br /&gt;
 * 5. OFB (Output Feedback Mode) - &lt;br /&gt;
 *&lt;br /&gt;
 *	High Level Algorithm :&lt;br /&gt;
 * 1. Generate a DES key&lt;br /&gt;
 * 2. Create the Cipher (Specify the Mode and Padding)&lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * Need for Padding :&lt;br /&gt;
 * Block ciphers operates on data blocks on fixed size n. &lt;br /&gt;
 * Since the data to be encrypted might not always be a multiple of n, the remainder of the bits are padded.&lt;br /&gt;
 * PKCS#5 Padding is what will be used in this program &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class DES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
		&lt;br /&gt;
		try{&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 1. Generate a DES key using KeyGenerator &lt;br /&gt;
		 * &lt;br /&gt;
		 */&lt;br /&gt;
		KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;DES&amp;quot;);&lt;br /&gt;
		SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step2. Create a Cipher by specifying the following parameters&lt;br /&gt;
		 * 			a. Algorithm name - here it is DES&lt;br /&gt;
		 * 			b. Mode - here it is CBC&lt;br /&gt;
		 * 			c. Padding - PKCS5Padding&lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		Cipher desCipher = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;); /* Must specify the mode explicitly as most JCE providers default to ECB mode!! */&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 3. Initialize the Cipher for Encryption &lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		desCipher.init(Cipher.ENCRYPT_MODE,secretKey);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 4. Encrypt the Data&lt;br /&gt;
		 *  		1. Declare / Initialize the Data. Here the data is of type String&lt;br /&gt;
		 *  		2. Convert the Input Text to Bytes&lt;br /&gt;
		 *  		3. Encrypt the bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		strDataToEncrypt = &amp;quot;Hello World of Encryption using DES &amp;quot;;&lt;br /&gt;
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
		byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt); &lt;br /&gt;
		strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
		System.out.println(&amp;quot;Cipher Text generated using DES with CBC mode and PKCS5 Padding is &amp;quot; +strCipherText);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 5. Decrypt the Data&lt;br /&gt;
		 *  		1. Initialize the Cipher for Decryption &lt;br /&gt;
		 *  		2. Decrypt the cipher bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		desCipher.init(Cipher.DECRYPT_MODE,secretKey,desCipher.getParameters());&lt;br /&gt;
		 //desCipher.init(Cipher.DECRYPT_MODE,secretKey);&lt;br /&gt;
		byte[] byteDecryptedText = desCipher.doFinal(byteCipherText);&lt;br /&gt;
		strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
		System.out.println(&amp;quot; Decrypted Text message is &amp;quot; +strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
			catch (NoSuchPaddingException noSuchPad)&lt;br /&gt;
			{&lt;br /&gt;
				System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
				catch (InvalidKeyException invalidKey)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (BadPaddingException badPadding)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (IllegalBlockSizeException illegalBlockSize)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (InvalidAlgorithmParameterException invalidParam)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
				}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Using_the_Java_Cryptographic_Extensions&amp;diff=175871</id>
		<title>Talk:Using the Java Cryptographic Extensions</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Using_the_Java_Cryptographic_Extensions&amp;diff=175871"/>
				<updated>2014-05-27T16:52:25Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: /* AES mode on this page is insecure */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;While performing AES encryption using SunJCE provider, I did not see usuage of the mode in the program provided. &lt;br /&gt;
I have few questions: &lt;br /&gt;
Do we really need to specify the mode when using AES? &lt;br /&gt;
Does PaddingException happen with AES and how do we prevent the PaddingException? &lt;br /&gt;
&lt;br /&gt;
Please let me know.&lt;br /&gt;
&lt;br /&gt;
== AES mode on this page is insecure ==&lt;br /&gt;
&lt;br /&gt;
The example for AES did not specify a mode which results in the default of ECB mode in most JCE providers!!  I fixed that line and commented, but this will need some other work as it is not providing any Initialization Vector (IV) to the AES encryption since it was using ECB mode originally (bad).  Will try to fix this with a working example.&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175870</id>
		<title>Using the Java Cryptographic Extensions</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Using_the_Java_Cryptographic_Extensions&amp;diff=175870"/>
				<updated>2014-05-27T16:48:55Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Note:==&lt;br /&gt;
''The code included in this article has not been reviewed and should not be used without proper analysis.  If you have reviewed the included code (or portions of it), please post your findings back to this page or to: stephen [at] corsaire.com.''&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Java Cryptographic Extensions (JCE) is a set of Java API's which provides cryptographic services such as encryption, secret Key Generation, Message Authentication code and Key Agreement. The ciphers supported by JCE include symmetric, asymmetric, block and stream ciphers. JCE was an optional package to JDK v 1.2.x and 1.3.x. JCE has been integrated into JDK v1.4.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JCE API's are implemented by Cryptographic Service Providers. Each of these cryptographic service providers implements the Service Provider Interface which specifies the functionalities which needs to be implemented by the service providers. Programmers can plugin any Service Providers for performing cryptographic functionalities provided by JCE. J2SE comes with a default provider named SunJCE.&lt;br /&gt;
&lt;br /&gt;
===Symmetric Encryption Algorithms provided by SunJCE===&lt;br /&gt;
# DES  - default keylength of 56 bits&lt;br /&gt;
# AES - &lt;br /&gt;
# RC2, RC4 and RC5&lt;br /&gt;
# IDEA&lt;br /&gt;
# Triple DES – default keylength 112 bits&lt;br /&gt;
# Blowfish – default keylength 56 bits&lt;br /&gt;
# PBEWithMD5AndDES&lt;br /&gt;
# PBEWithHmacSHA1AndDESede&lt;br /&gt;
# DES ede&lt;br /&gt;
&lt;br /&gt;
===Modes of Encryption===&lt;br /&gt;
# ECB&lt;br /&gt;
# CBC&lt;br /&gt;
# CFB&lt;br /&gt;
# OFB&lt;br /&gt;
# PCBC&lt;br /&gt;
&lt;br /&gt;
===Asymmetric Encryption Algorithms implemented by SunJCE===&lt;br /&gt;
# RSA&lt;br /&gt;
# Diffie-Hellman – default keylength 1024 bits&lt;br /&gt;
&lt;br /&gt;
===Hashing / Message Digest Algorithms implemented by SunJCE===&lt;br /&gt;
# MD5 – default size 64 bytes&lt;br /&gt;
# SHA1 - default size 64 bytes&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===SecureRandom===&lt;br /&gt;
SecureRandom class is used to generate a cryptographically strong pseudo random number by using a PRNG Algorithm.&lt;br /&gt;
The following are the advantages of using SecureRandom over Random.&lt;br /&gt;
1. SecureRandom produces a cryptographically strong pseudo random number generator. &lt;br /&gt;
2. SecureRandom produces cryptographically strong sequences as described in &lt;br /&gt;
[http://www.ietf.org/rfc/rfc1750.txt RFC 1750: Randomness Recommendations for Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the functionality for Generating a Secure Random Number.&lt;br /&gt;
 *  &lt;br /&gt;
 * There are 2 ways to generate a  Random number through SecureRandom.&lt;br /&gt;
 * 1. By calling nextBytes method to generate Random Bytes&lt;br /&gt;
 * 2. Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class SecureRandomGen {&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * @param args&lt;br /&gt;
	 */&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
	        // Initialize a secure random number generator&lt;br /&gt;
	        SecureRandom secureRandom = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 1 - Calling nextBytes method to generate Random Bytes&lt;br /&gt;
	        byte[] bytes = new byte[512];&lt;br /&gt;
	        secureRandom.nextBytes(bytes); &lt;br /&gt;
	        &lt;br /&gt;
	        // Printing the SecureRandom number by calling secureRandom.nextDouble()&lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated by calling nextBytes() is &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	    &lt;br /&gt;
	        // Method 2 - Using setSeed(byte[]) to reseed a Random object&lt;br /&gt;
	        int seedByteCount = 10;&lt;br /&gt;
	        byte[] seed = secureRandom.generateSeed(seedByteCount);   &lt;br /&gt;
	        &lt;br /&gt;
	        // TBR System.out.println(&amp;quot; Seed value is &amp;quot; + new BASE64Encoder().encode(seed));&lt;br /&gt;
	    &lt;br /&gt;
	        secureRandom.setSeed(seed);&lt;br /&gt;
	        &lt;br /&gt;
	        System.out.println(&amp;quot; Secure Random # generated using setSeed(byte[]) is  &amp;quot; + secureRandom.nextDouble());&lt;br /&gt;
	        &lt;br /&gt;
	    } catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== AES Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.java.crypto;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using AES&lt;br /&gt;
 * 2. Decryption using AES&lt;br /&gt;
 * &lt;br /&gt;
 * High Level Algorithm :&lt;br /&gt;
 * 1. Generate a DES key (specify the Key size during this phase) &lt;br /&gt;
 * 2. Create the Cipher &lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class AES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
		&lt;br /&gt;
		try{&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 1. Generate an AES key using KeyGenerator&lt;br /&gt;
		 *  		Initialize the keysize to 128 &lt;br /&gt;
		 * &lt;br /&gt;
		 */&lt;br /&gt;
		KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
		keyGen.init(128);&lt;br /&gt;
		SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step2. Create a Cipher by specifying the following parameters&lt;br /&gt;
		 * 			a. Algorithm name - here it is AES&lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		Cipher aesCipher = Cipher.getInstance(&amp;quot;AES/CBC&amp;quot;); /* Must specify the mode explicitly as most JCE providers default to ECB mode!! */&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 3. Initialize the Cipher for Encryption &lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		aesCipher.init(Cipher.ENCRYPT_MODE,secretKey);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 4. Encrypt the Data&lt;br /&gt;
		 *  		1. Declare / Initialize the Data. Here the data is of type String&lt;br /&gt;
		 *  		2. Convert the Input Text to Bytes&lt;br /&gt;
		 *  		3. Encrypt the bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		strDataToEncrypt = &amp;quot;Hello World of Encryption using AES &amp;quot;;&lt;br /&gt;
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
		byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt); &lt;br /&gt;
		strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
		System.out.println(&amp;quot;Cipher Text generated using AES is &amp;quot; +strCipherText);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 5. Decrypt the Data&lt;br /&gt;
		 *  		1. Initialize the Cipher for Decryption &lt;br /&gt;
		 *  		2. Decrypt the cipher bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		aesCipher.init(Cipher.DECRYPT_MODE,secretKey,aesCipher.getParameters());&lt;br /&gt;
		byte[] byteDecryptedText = aesCipher.doFinal(byteCipherText);&lt;br /&gt;
		strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
		System.out.println(&amp;quot; Decrypted Text message is &amp;quot; +strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
			catch (NoSuchPaddingException noSuchPad)&lt;br /&gt;
			{&lt;br /&gt;
				System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
				catch (InvalidKeyException invalidKey)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (BadPaddingException badPadding)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (IllegalBlockSizeException illegalBlockSize)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (InvalidAlgorithmParameterException invalidParam)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
				}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Des Encryption and Decryption ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.owasp.crypto;&lt;br /&gt;
&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.InvalidAlgorithmParameterException;&lt;br /&gt;
import javax.crypto.NoSuchPaddingException;&lt;br /&gt;
import javax.crypto.BadPaddingException;&lt;br /&gt;
import javax.crypto.IllegalBlockSizeException;&lt;br /&gt;
&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author Joe Prasanna Kumar&lt;br /&gt;
 * This program provides the following cryptographic functionalities&lt;br /&gt;
 * 1. Encryption using DES&lt;br /&gt;
 * 2. Decryption using DES&lt;br /&gt;
 * &lt;br /&gt;
 * The following modes of DES encryption are supported by SUNJce provider &lt;br /&gt;
 * 1. ECB (Electronic code Book) - Every plaintext block is encrypted separately &lt;br /&gt;
 * 2. CBC (Cipher Block Chaining) - Every plaintext block is XORed with the previous ciphertext block&lt;br /&gt;
 * 3. PCBC (Propogating Cipher Block Chaining) - &lt;br /&gt;
 * 4. CFB (Cipher Feedback Mode) - The previous ciphertext block is encrypted and this enciphered block is XORed with the plaintext block to produce the corresponding ciphertext block &lt;br /&gt;
 * 5. OFB (Output Feedback Mode) - &lt;br /&gt;
 *&lt;br /&gt;
 *	High Level Algorithm :&lt;br /&gt;
 * 1. Generate a DES key&lt;br /&gt;
 * 2. Create the Cipher (Specify the Mode and Padding)&lt;br /&gt;
 * 3. To Encrypt : Initialize the Cipher for Encryption&lt;br /&gt;
 * 4. To Decrypt : Initialize the Cipher for Decryption&lt;br /&gt;
 * &lt;br /&gt;
 * Need for Padding :&lt;br /&gt;
 * Block ciphers operates on data blocks on fixed size n. &lt;br /&gt;
 * Since the data to be encrypted might not always be a multiple of n, the remainder of the bits are padded.&lt;br /&gt;
 * PKCS#5 Padding is what will be used in this program &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class DES {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		&lt;br /&gt;
		String strDataToEncrypt = new String();&lt;br /&gt;
		String strCipherText = new String();&lt;br /&gt;
		String strDecryptedText = new String();&lt;br /&gt;
		&lt;br /&gt;
		try{&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 1. Generate a DES key using KeyGenerator &lt;br /&gt;
		 * &lt;br /&gt;
		 */&lt;br /&gt;
		KeyGenerator keyGen = KeyGenerator.getInstance(&amp;quot;DES&amp;quot;);&lt;br /&gt;
		SecretKey secretKey = keyGen.generateKey();&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step2. Create a Cipher by specifying the following parameters&lt;br /&gt;
		 * 			a. Algorithm name - here it is DES&lt;br /&gt;
		 * 			b. Mode - here it is CBC&lt;br /&gt;
		 * 			c. Padding - PKCS5Padding&lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		Cipher desCipher = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;); /* Must specify the mode explicitly as most JCE providers default to ECB mode!! */&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 3. Initialize the Cipher for Encryption &lt;br /&gt;
		 */&lt;br /&gt;
		&lt;br /&gt;
		desCipher.init(Cipher.ENCRYPT_MODE,secretKey);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 4. Encrypt the Data&lt;br /&gt;
		 *  		1. Declare / Initialize the Data. Here the data is of type String&lt;br /&gt;
		 *  		2. Convert the Input Text to Bytes&lt;br /&gt;
		 *  		3. Encrypt the bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		strDataToEncrypt = &amp;quot;Hello World of Encryption using DES &amp;quot;;&lt;br /&gt;
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();&lt;br /&gt;
		byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt); &lt;br /&gt;
		strCipherText = new BASE64Encoder().encode(byteCipherText);&lt;br /&gt;
		System.out.println(&amp;quot;Cipher Text generated using DES with CBC mode and PKCS5 Padding is &amp;quot; +strCipherText);&lt;br /&gt;
		&lt;br /&gt;
		/**&lt;br /&gt;
		 *  Step 5. Decrypt the Data&lt;br /&gt;
		 *  		1. Initialize the Cipher for Decryption &lt;br /&gt;
		 *  		2. Decrypt the cipher bytes using doFinal method &lt;br /&gt;
		 */&lt;br /&gt;
		desCipher.init(Cipher.DECRYPT_MODE,secretKey,desCipher.getParameters());&lt;br /&gt;
		 //desCipher.init(Cipher.DECRYPT_MODE,secretKey);&lt;br /&gt;
		byte[] byteDecryptedText = desCipher.doFinal(byteCipherText);&lt;br /&gt;
		strDecryptedText = new String(byteDecryptedText);&lt;br /&gt;
		System.out.println(&amp;quot; Decrypted Text message is &amp;quot; +strDecryptedText);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		catch (NoSuchAlgorithmException noSuchAlgo)&lt;br /&gt;
		{&lt;br /&gt;
			System.out.println(&amp;quot; No Such Algorithm exists &amp;quot; + noSuchAlgo);&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
			catch (NoSuchPaddingException noSuchPad)&lt;br /&gt;
			{&lt;br /&gt;
				System.out.println(&amp;quot; No Such Padding exists &amp;quot; + noSuchPad);&lt;br /&gt;
			}&lt;br /&gt;
		&lt;br /&gt;
				catch (InvalidKeyException invalidKey)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Key &amp;quot; + invalidKey);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (BadPaddingException badPadding)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Bad Padding &amp;quot; + badPadding);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (IllegalBlockSizeException illegalBlockSize)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Illegal Block Size &amp;quot; + illegalBlockSize);&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				catch (InvalidAlgorithmParameterException invalidParam)&lt;br /&gt;
				{&lt;br /&gt;
					System.out.println(&amp;quot; Invalid Parameter &amp;quot; + invalidParam);&lt;br /&gt;
				}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=175869</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=175869"/>
				<updated>2014-05-27T16:43:36Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: /* Jason Axley */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
Blog:  http://truthimperative.axley.net&amp;lt;br /&amp;gt;&lt;br /&gt;
http://www.linkedin.com/in/axleyjc&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Former .Net security guy turned mobile app security guy.  This information needs an update:&lt;br /&gt;
&lt;br /&gt;
[https://www.owasp.org/index.php/Category:OWASP_.NET_Project OWASP_.NET_Project] volunteer&amp;lt;br /&amp;gt;&lt;br /&gt;
Participant in the [[Seattle|OWASP Seattle Local Chapter]]&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning to work on these projects in some capacity:&lt;br /&gt;
&lt;br /&gt;
* OWASP [[.Net CSRF Guard|CSRFGuard .Net port]] (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements [[DN_BOFinder]]&lt;br /&gt;
* [[OWASP SiteGenerator]] spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* [[ESAPI|.Net Enterprise Security API]] / mod_security port [[DefApp]] enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=98289</id>
		<title>Summit 2011 Attendee/Attendee091</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=98289"/>
				<updated>2011-01-04T17:02:55Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:&amp;lt;includeonly&amp;gt;{{{1}}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;OWASP 2011 Global Summit Attendee Tab&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_name1 =&lt;br /&gt;
| summit_attendee_email1 =&lt;br /&gt;
| summit_attendee_wiki_username1 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_company =&lt;br /&gt;
|-&lt;br /&gt;
| Project Leadership (less than 6 months old) = &lt;br /&gt;
| Project Leadership (more than 6 months old) =&lt;br /&gt;
| Release Leadership (less than 6 months old) = &lt;br /&gt;
| Release Leadership (more than 6 months old) = &lt;br /&gt;
| Project Contribution  (less than 6 months old) = &lt;br /&gt;
| Project Contribution  (more than 6 months old) = &lt;br /&gt;
| Release Contribution (less than 6 months old) =  &lt;br /&gt;
| Release Contribution (more than 6 months old) = &lt;br /&gt;
| Committee Membership = &lt;br /&gt;
| Chapter Co-Leadership = &lt;br /&gt;
| Conference Co-Leadership =  &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_current_owasp_involvement_name1 =&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_1 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name2 =&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name5 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name1 =&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_1 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_1 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name2 =&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_2 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name3 =&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_3 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_4 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name5 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_5 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_owasp_sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name2 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_2 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name2 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_2 =  &lt;br /&gt;
|-&lt;br /&gt;
| reason_for_sponsorship =&lt;br /&gt;
|-&lt;br /&gt;
| status =&lt;br /&gt;
|-&lt;br /&gt;
| letter sent to sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| notes for Kate =  &lt;br /&gt;
|-&lt;br /&gt;
| attendee_name_mask = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Attendee091&lt;br /&gt;
| attendee_home_page = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Summit_2011_Attendee/Attendee091&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee104&amp;diff=98288</id>
		<title>Summit 2011 Attendee/Attendee104</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee104&amp;diff=98288"/>
				<updated>2011-01-04T17:00:12Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:&amp;lt;includeonly&amp;gt;{{{1}}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;OWASP 2011 Global Summit Attendee Tab&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_name1 = Jason Axley&lt;br /&gt;
| summit_attendee_email1 = jason@axley.net&lt;br /&gt;
| summit_attendee_wiki_username1 = jaxley&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_company = JP Morgan Chase&lt;br /&gt;
|-&lt;br /&gt;
| Project Leadership (less than 6 months old) = &lt;br /&gt;
| Project Leadership (more than 6 months old) = .Net CSRF Guard&lt;br /&gt;
| Release Leadership (less than 6 months old) = &lt;br /&gt;
| Release Leadership (more than 6 months old) = &lt;br /&gt;
| Project Contribution  (less than 6 months old) = &lt;br /&gt;
| Project Contribution  (more than 6 months old) = &lt;br /&gt;
| Release Contribution (less than 6 months old) =  &lt;br /&gt;
| Release Contribution (more than 6 months old) = &lt;br /&gt;
| Committee Membership = &lt;br /&gt;
| Chapter Co-Leadership = &lt;br /&gt;
| Conference Co-Leadership =  &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_current_owasp_involvement_name1 = OWASP Seattle Chapter participant&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_1 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name2 = OWASP .Net project member (wrote .Net CSRFGuard)&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name5 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name1 = CSRF eradication in ASP.Net MVC (making what's provided better)&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_1 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_1 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name2 = XSS eradication in ASP.Net MVC (patterns and guidance and application of new .Net 4.0 IHtmlString, etc.)&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_2 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name3 = ASP.Net code analysis rule development&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_3 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_4 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name5 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_5 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_owasp_sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name2 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_2 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name2 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_2 =  &lt;br /&gt;
|-&lt;br /&gt;
| reason_for_sponsorship =&lt;br /&gt;
|-&lt;br /&gt;
| status = scheduling conflict (cannot attend)&lt;br /&gt;
|-&lt;br /&gt;
| letter sent to sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| notes for Kate =  &lt;br /&gt;
|-&lt;br /&gt;
| attendee_name_mask = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Attendee091&lt;br /&gt;
| attendee_home_page = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Summit_2011_Attendee/Attendee091&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97502</id>
		<title>Summit 2011 Attendee/Attendee091</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97502"/>
				<updated>2010-12-22T08:21:50Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:&amp;lt;includeonly&amp;gt;{{{1}}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;OWASP 2011 Global Summit Attendee Tab&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_name1 = Jason Axley&lt;br /&gt;
| summit_attendee_email1 = jason@axley.net&lt;br /&gt;
| summit_attendee_wiki_username1 = jaxley&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_company = JP Morgan Chase&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_current_owasp_involvement_name1 = OWASP Seattle Chapter participant&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_1 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name2 = OWASP .Net project member (wrote .Net CSRFGuard)&lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name5 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name1 = CSRF eradication in ASP.Net MVC (making what's provided better)&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_1 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_1 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name2 = XSS eradication in ASP.Net MVC (patterns and guidance and application of new .Net 4.0 IHtmlString, etc.)&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_2 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name3 = ASP.Net code analysis rule development&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_3 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_4 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name5 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_5 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_owasp_sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name1 = JP Morgan Chase (pending)&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name2 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_2 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name2 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_2 =  &lt;br /&gt;
|-&lt;br /&gt;
| reason_for_sponsorship = OWASP.Net project needs to catch up with Java in maturity and guidance&lt;br /&gt;
|-&lt;br /&gt;
| status = seeking funds&lt;br /&gt;
|-&lt;br /&gt;
| letter sent to sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| notes for Kate =  &lt;br /&gt;
|-&lt;br /&gt;
| attendee_name_mask = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Attendee092&lt;br /&gt;
| attendee_home_page = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Summit_2011_Attendee/Attendee092&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97501</id>
		<title>Summit 2011 Attendee/Attendee091</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97501"/>
				<updated>2010-12-22T08:16:44Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:&amp;lt;includeonly&amp;gt;{{{1}}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;OWASP 2011 Global Summit Attendee Tab&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_name1 = Jason Axley&lt;br /&gt;
| summit_attendee_email1 = jason@axley.net&lt;br /&gt;
| summit_attendee_wiki_username1 = jaxley&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_company = JP Morgan Chase&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_current_owasp_involvement_name1 =  &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_1 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name5 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name1 =  &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_1 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_1 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_2 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_3 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_4 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name5 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_5 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_owasp_sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name2 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_2 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name2 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_2 =  &lt;br /&gt;
|-&lt;br /&gt;
| reason_for_sponsorship = &lt;br /&gt;
|-&lt;br /&gt;
| status = &lt;br /&gt;
|-&lt;br /&gt;
| letter sent to sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| notes for Kate =  &lt;br /&gt;
|-&lt;br /&gt;
| attendee_name_mask = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Attendee092&lt;br /&gt;
| attendee_home_page = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Summit_2011_Attendee/Attendee092&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97500</id>
		<title>Summit 2011 Attendee/Attendee091</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Summit_2011_Attendee/Attendee091&amp;diff=97500"/>
				<updated>2010-12-22T08:14:54Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:&amp;lt;img class=&amp;quot;FCK__MWIncludeonly&amp;quot; src=&amp;quot;http://www.owasp.org/extensions/FCKeditor/fckeditor/editor/images/spacer.gif&amp;quot; _fckfakelement=&amp;quot;true&amp;quot; _fckrealelement=&amp;quot;3&amp;quot; _fck_mw_includeonly=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;img class=&amp;quot;FCK__MWNoinclude&amp;quot; src=&amp;quot;http://www.owasp.org/extensions/FCKeditor/fckeditor/editor/images/spacer.gif&amp;quot; _fckfakelement=&amp;quot;true&amp;quot; _fckrealelement=&amp;quot;2&amp;quot; _fck_mw_noinclude=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_name1 = Jason Axley&lt;br /&gt;
| summit_attendee_email1 = jason@axley.net&lt;br /&gt;
| summit_attendee_wiki_username1 = jaxley&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_company = JP Morgan Chase&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_current_owasp_involvement_name1 =  &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_1 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_2 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_3 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_4 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_name5 = &lt;br /&gt;
| summit_attendee_current_owasp_involvement_url_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name1 = CSRF prevention in .Net&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_1 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_1 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name2 = XSS prevention in .Net MVC2 via IHtmlString, etc.&lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_2 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_2 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_3 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_3 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_4 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_4 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_name5 = &lt;br /&gt;
| summit_attendee_reason_for_summit_participation_url_5 = &lt;br /&gt;
| notes_reason_for_participating_issues_to_be_discussed_5 = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_owasp_sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name1 = JP Morgan Chase (pending)&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_1 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_name2 =&lt;br /&gt;
| summit_attendee_summit_time_paid_by_url_2 =&lt;br /&gt;
|-&lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_1 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_name2 = &lt;br /&gt;
| summit_attendee_summit_expenses_paid_by_url_2 =  &lt;br /&gt;
|-&lt;br /&gt;
| reason_for_sponsorship = OWASP .Net needs to catch up with Java capabilities and patterns&lt;br /&gt;
|-&lt;br /&gt;
| status = &lt;br /&gt;
|-&lt;br /&gt;
| letter sent to sponsor = &lt;br /&gt;
|-&lt;br /&gt;
| notes for Kate =  &lt;br /&gt;
|-&lt;br /&gt;
| attendee_name_mask = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Attendee091&lt;br /&gt;
| attendee_home_page = &amp;lt;!--Please replace DO NOT EDIT this string --&amp;gt; Summit_2011_Attendee/Attendee091&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_.NET_Active_Projects&amp;diff=30715</id>
		<title>OWASP .NET Active Projects</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_.NET_Active_Projects&amp;diff=30715"/>
				<updated>2008-06-08T03:25:05Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: Added .Net CSRF Guard that was missing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===OWASP Projects===&lt;br /&gt;
'''Note:''' &lt;br /&gt;
The following releases are available on the [https://sourceforge.net/project/showfiles.php?group_id=64424&amp;amp;package_id=105632 dotNET section] of the [https://sourceforge.net/projects/owasp/ SourceForge OWASP Project pages]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Owasp SiteGenerator]] (sponsored by Foundstone)&lt;br /&gt;
* [[Owasp Report Generator]]&lt;br /&gt;
* [[ANBS]] (Asp.Net Baseline Security) - includes the tools [[SAM'SHE]] (Security Analyzer for Microsoft's Shared Hosting Environments) and [[Online IIS Metabase Explorer]]&lt;br /&gt;
* [[ASP.NET Reflector]]&lt;br /&gt;
* [[ANSA]] (Asp.Net Security Analyzer) - first tool developed by Dinis Cruz that hilights the security problems of Full Trust Asp.Net code (contains Proof of Concept tests (i.e. exploits))&lt;br /&gt;
* [[DefApp]] - Partial port of ModSecurity to the .Net Platform &lt;br /&gt;
* [[Owasp FOSBBWAS (code name Beretta)]]&lt;br /&gt;
* [[.Net Assembly Analyzer]]&lt;br /&gt;
* [[OWASP_Tiger|OWASP Tiger]]&lt;br /&gt;
* [[.Net CSRF Guard]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following OWASP projects are hosted on other project hosting sites:&lt;br /&gt;
&lt;br /&gt;
* [http://code.google.com/p/owasp-esapi-dotnet/ OWASP ESAPI .NET]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
===Active Project Workspaces===&lt;br /&gt;
*[http://trac2.assembla.com/owaspdotnet/query?status=new&amp;amp;status=assigned&amp;amp;status=reopened&amp;amp;group=type&amp;amp;reporter=%7E&amp;amp;eta=%7E Task and Research projects]&lt;br /&gt;
*FXCop Ruleset&lt;br /&gt;
*Sprajax&lt;br /&gt;
*CSSpider&lt;br /&gt;
*[http://www.assembla.com/wiki/show/owaspdotnet SCAN (Code Scanner)]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Related Open Source Projects===&lt;br /&gt;
* [[Hacme Bank]] (Foundstone tool)&lt;br /&gt;
* [[.NetMon]] (Foundstone tool)&lt;br /&gt;
* [[Validator.NET]] (Foundstone tool)&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Source Code Repositories===&lt;br /&gt;
Any repository that allows public access and has terms of service that holds no claim on the content that our members upload is generally o.k.  The following repos are popular among the members:&lt;br /&gt;
&lt;br /&gt;
*[http://www.assembla.com/wiki/show/owaspdotnet OWASP @ Assembla.com]&lt;br /&gt;
*[http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=owasp OWASP @ Codeplex]&lt;br /&gt;
*[http://code.google.com/p/owasp-code-central/ OWASP @ Google Code]&lt;br /&gt;
*[http://sourceforge.net/projects/owasp/ OWASP @ SourceForge]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Starting your own .NET Project===&lt;br /&gt;
If you're interested in starting your own project, please read [https://www.owasp.org/index.php/How_to_Start_an_OWASP_Project How to Start an OWASP Project].  Remember to add the tag: &amp;lt;nowiki&amp;gt;[[Category:OWASP .NET Project]]&amp;lt;/nowiki&amp;gt; to the end of new projects so that they're properly categorized.&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23537</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23537"/>
				<updated>2007-11-19T05:55:50Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
Blog:  http://juxtaposition.axley.net&amp;lt;br /&amp;gt;&lt;br /&gt;
http://www.linkedin.com/in/axleyjc&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.owasp.org/index.php/Category:OWASP_.NET_Project OWASP_.NET_Project] volunteer&amp;lt;br /&amp;gt;&lt;br /&gt;
Participant in the [[Seattle|OWASP Seattle Local Chapter]]&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning to work on these projects in some capacity:&lt;br /&gt;
&lt;br /&gt;
* OWASP [[.Net CSRF Guard|CSRFGuard .Net port]] (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements [[DN_BOFinder]]&lt;br /&gt;
* [[OWASP SiteGenerator]] spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* [[ESAPI|.Net Enterprise Security API]] / mod_security port [[DefApp]] enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23536</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23536"/>
				<updated>2007-11-19T05:52:02Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
Blog:  http://juxtaposition.axley.net&amp;lt;br /&amp;gt;&lt;br /&gt;
http://www.linkedin.com/in/axleyjc&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_.NET_Project]] volunteer&amp;lt;br /&amp;gt;&lt;br /&gt;
Participant in the [[Seattle|OWASP Seattle Local Chapter]]&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning to work on these projects in some capacity:&lt;br /&gt;
&lt;br /&gt;
* OWASP [[.Net CSRF Guard|CSRFGuard .Net port]] (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements [[DN_BOFinder]]&lt;br /&gt;
* [[OWASP SiteGenerator]] spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* [[ESAPI|.Net Enterprise Security API]] / mod_security port [[DefApp]] enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23535</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23535"/>
				<updated>2007-11-19T05:51:38Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
Blog:  http://juxtaposition.axley.net&amp;lt;br /&amp;gt;&lt;br /&gt;
http://www.linkedin.com/in/axleyjc&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_.NET_Project]] volunteer&amp;lt;br /&amp;gt;&lt;br /&gt;
Participant in the [[Seattle|OWASP Seattle Local Chapter]]&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning these projects:&lt;br /&gt;
&lt;br /&gt;
* OWASP [[.Net CSRF Guard|CSRFGuard .Net port]] (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements [[DN_BOFinder]]&lt;br /&gt;
* [[OWASP SiteGenerator]] spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* [[ESAPI|.Net Enterprise Security API]] / mod_security port [[DefApp]] enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23534</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23534"/>
				<updated>2007-11-19T05:41:49Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
Blog:  http://juxtaposition.axley.net&lt;br /&gt;
http://www.linkedin.com/in/axleyjc&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_.NET_Project]] volunteer&amp;lt;br /&amp;gt;&lt;br /&gt;
Participant in the [[Seattle|OWASP Seattle Local Chapter]]&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning these projects:&lt;br /&gt;
&lt;br /&gt;
* OWASP [[.Net CSRF Guard|CSRFGuard .Net port]] (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements [[DN_BOFinder]]&lt;br /&gt;
* [[OWASP SiteGenerator]] spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* [[ESAPI|.Net Enterprise Security API]] / mod_security port [[DefApp]] enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23527</id>
		<title>CSRF Guard</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23527"/>
				<updated>2007-11-19T04:47:04Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Just when developers are starting to run in circles over [[Cross Site Scripting]], the [http://www.darkreading.com/document.asp?doc_id=107651&amp;amp;WT.svl=news1_2 'sleeping giant'] awakes for yet another web-catastrophe. [[Cross-Site Request Forgery]] (CSRF) is an attack whereby the victim is tricked into loading information from or submitting information to a web application for which they are currently authenticated. The problem is that the web application has no means of verifying the integrity of the request.&lt;br /&gt;
&lt;br /&gt;
==Recommended Prevention Measure: Unique Request Tokens==&lt;br /&gt;
&lt;br /&gt;
The core issue with CSRF attacks is that form submission can be imitated with forged requests. The application must be able to differentiate between legal requests and forged requests. Since all headers, cookies, and credentials will be submitted with both legal and forged requests, the only method of truly verifying the integrity of the request is with a uniquely identifiable token in the form of an HTTP parameter. When the user first visits the site, the application will generate and store a ''session specific'' unique request token. This session specific unique request token is then placed in each form and link of the HTML response, ensuring that this value will be submitted with the next request. For each subsequent request, the application must verify the existence of the unique token parameter and compare its value to that of the value stored in the user's session. The security of the approach is based on the fact that this unique token value is specific to a user's session and is ''hard to guess.'' Therefore, it is imperative that this value is large and cryptographically secure.&lt;br /&gt;
&lt;br /&gt;
:*'''UPDATE:''' There have been discussions suggesting that the unique request token can be compromised using JavaScript. This attack implies that the application also contains a Cross-Site scripting vulnerability, which is a more severe issue than Cross-Site request forgery. The first Myspace worm worked in this manner where it used a Cross Site Scripting vulnerability to forge requests to update a user's profile, where the user profile update mechanism was protected with an antiCSRF defense mechanism similar to what is provided by this filter. You can mitigate this risk somewhat by making your form key AND value a CSRF Guard-type token.&lt;br /&gt;
&lt;br /&gt;
==Example: The Java CSRF Guard==&lt;br /&gt;
&lt;br /&gt;
=== Java EE Filter ===&lt;br /&gt;
&lt;br /&gt;
Java EE filters provide the ability to intercept, view, and modify both the request and associated response for the requesting client. Filters are inserted and executed by the Java EE container's deployment descriptor (web.xml) file. For example, if an HTTP request for a JSP page hits our Apache web server, the request is sent to Tomcat for processing. Before Tomcat executes the code inside of the JSP, the request must be passed along a chain of Java EE filters. The following snippet illustrates how to declare and map a filter to a particular URI-space in web.xml:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;filter&amp;gt;&lt;br /&gt;
    &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
    &amp;lt;filter-class&amp;gt;org.owasp.csrf.CSRFGuard&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
      &amp;lt;init-param&amp;gt;&lt;br /&gt;
        &amp;lt;param-name&amp;gt;error-page&amp;lt;/param-name&amp;gt;&lt;br /&gt;
        &amp;lt;param-value&amp;gt;error.jsp&amp;lt;/param-value&amp;gt;&lt;br /&gt;
      &amp;lt;/init-param&amp;gt;&lt;br /&gt;
 &amp;lt;/filter&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;
   &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
   &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
 &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Implementing the CSRF Guard as a Java EE Filter gives us the ability to verify the integrity of the request before it ever hits our web application.&lt;br /&gt;
&lt;br /&gt;
=== Secure Random ===&lt;br /&gt;
&lt;br /&gt;
When implementing the CSRF Guard, we must ensure that the unique request token is cryptographically strong. After all, our implementation relies on the principle that the unique token is difficult to guess. If the unique request token can be easily guessed then a CSRF attack can be executed.&lt;br /&gt;
&lt;br /&gt;
The following code snippet generates a BASE64 encoded string of 'size' bytes:&lt;br /&gt;
&lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
&lt;br /&gt;
The following Java EE Filter will attempt to verify the integrity of the request by comparing the OWASP_CSRFTOKEN HTTP parameter value with that of the OWASP_CSRFTOKEN session attribute. If the two values do not match, then the request is forged and we invoked the doError() method. This method will invalidate the existing session and redirect the user to a page specified by the filter init-parameter &amp;quot;error-page&amp;quot;. If the parameter value equals the corresponding session attribute value, then we call doChain() and pass the request to the webapplication. Once the web application is finished processing the request, the buildLinkParameters() method will search the HTML response for forms and links and insert the appropriate OWASP_CSRFTOKEN parameter value. Unfortunately, the dependency on an HTML response means that the current filter may not work with some Web 2.0 applications. Furthermore, the filter only modifies response objects whose &amp;quot;Content-Type&amp;quot; header is text based. If your web application neglects to set the appropriate value for the &amp;quot;Content-Type&amp;quot; header, then the CSRF Guard will not make the appropriate changes to the HTML response and each subsequent request will be considered a violation.&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * CSRFGuard.java&lt;br /&gt;
  *&lt;br /&gt;
  * Created on January 2, 2007, 11:35 AM&lt;br /&gt;
  *&lt;br /&gt;
  * Copyright (C) 2007 Eric Sheridan&lt;br /&gt;
  *&lt;br /&gt;
  * This library is free software; you can redistribute it and/or&lt;br /&gt;
  * modify it under the terms of the GNU Lesser General Public&lt;br /&gt;
  * License as published by the Free Software Foundation; either&lt;br /&gt;
  * version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;
  *&lt;br /&gt;
  * This library is distributed in the hope that it will be useful,&lt;br /&gt;
  * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU&lt;br /&gt;
  * Lesser General Public License for more details.&lt;br /&gt;
  *&lt;br /&gt;
  * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
  * License along with this library; if not, write to the Free Software&lt;br /&gt;
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 package org.owasp.csrf;&lt;br /&gt;
  &lt;br /&gt;
 import java.io.OutputStream;&lt;br /&gt;
 import java.io.IOException;&lt;br /&gt;
 import java.security.SecureRandom;&lt;br /&gt;
 import java.util.regex.Pattern;&lt;br /&gt;
 import javax.servlet.Filter;&lt;br /&gt;
 import javax.servlet.FilterChain;&lt;br /&gt;
 import javax.servlet.FilterConfig;&lt;br /&gt;
 import javax.servlet.ServletException;&lt;br /&gt;
 import javax.servlet.ServletRequest;&lt;br /&gt;
 import javax.servlet.ServletResponse;&lt;br /&gt;
 import javax.servlet.http.HttpSession;&lt;br /&gt;
 import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
 import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
 import sun.misc.BASE64Encoder;&lt;br /&gt;
 import org.owasp.csrf.http.MutableHttpResponse;&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *&lt;br /&gt;
  * @author esheridan&lt;br /&gt;
  */&lt;br /&gt;
 public class CSRFGuard implements Filter {&lt;br /&gt;
    public final static String OWASP_CSRFTOKEN = &amp;quot;OWASP_CSRFTOKEN&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern FORM_PATTERN = Pattern.compile(&amp;quot;(?i)&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern SKIPPABLE_PATTERN = Pattern.compile(&amp;quot;.*\\.(gif|jpg|png|css|js|ico|swf|axd.*)$&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    private String errorPage = null;&lt;br /&gt;
    &lt;br /&gt;
    public void init(FilterConfig config) {&lt;br /&gt;
        errorPage = config.getInitParameter(&amp;quot;error-page&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {&lt;br /&gt;
        if(request instanceof HttpServletRequest &amp;amp;&amp;amp; response instanceof HttpServletResponse) {&lt;br /&gt;
            try {&lt;br /&gt;
                HttpServletRequest hRequest = (HttpServletRequest)request;&lt;br /&gt;
                MutableHttpResponse mResponse = new MutableHttpResponse((HttpServletResponse)response);&lt;br /&gt;
                HttpSession session = hRequest.getSession(false);&lt;br /&gt;
                &lt;br /&gt;
                if(session != null) {&lt;br /&gt;
                    if(!hasCSRFToken(session)) {&lt;br /&gt;
                        setCSRFToken(session);&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else if(isSkippable(hRequest) || isValidRequest(session, hRequest)) {&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else {&lt;br /&gt;
                        doError(session, (HttpServletResponse)response);&lt;br /&gt;
                    }&lt;br /&gt;
                } else {&lt;br /&gt;
                    chain.doFilter(request, response);&lt;br /&gt;
                }&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
                e.printStackTrace();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doError(HttpSession session, HttpServletResponse response) throws IOException {&lt;br /&gt;
        session.invalidate();&lt;br /&gt;
        response.sendRedirect(errorPage);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doChain(HttpServletRequest request, MutableHttpResponse mResponse, ServletResponse response, FilterChain chain) throws IOException, ServletException {&lt;br /&gt;
        OutputStream out = response.getOutputStream();&lt;br /&gt;
        &lt;br /&gt;
        chain.doFilter(request, mResponse);&lt;br /&gt;
        &lt;br /&gt;
        String contentType = mResponse.getContentType();&lt;br /&gt;
        String token = getCSRFToken(request.getSession());&lt;br /&gt;
        &lt;br /&gt;
        if(contentType != null &amp;amp;&amp;amp; contentType.startsWith(&amp;quot;text&amp;quot;)) {&lt;br /&gt;
            String content = new String(mResponse.getContent());&lt;br /&gt;
            content = getModifiedResponse(token, content);&lt;br /&gt;
            byte[] result = content.getBytes();&lt;br /&gt;
            &lt;br /&gt;
            response.setContentLength(result.length);&lt;br /&gt;
            out.write(result);&lt;br /&gt;
        } else {&lt;br /&gt;
            out.write(mResponse.getContent());&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        out.close();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getModifiedResponse(String token, String content) {&lt;br /&gt;
        content = buildFormParameters(content, token);&lt;br /&gt;
        content = buildLinkParameters(content, token);&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getCSRFToken(HttpSession session) {&lt;br /&gt;
        return (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean hasCSRFToken(HttpSession session) {&lt;br /&gt;
        return getCSRFToken(session) != null;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void setCSRFToken(HttpSession session) {&lt;br /&gt;
        session.setAttribute(OWASP_CSRFTOKEN, generateCSRFToken());&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken() {&lt;br /&gt;
        return generateCSRFToken(32);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random).replace('+', '_');&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isSkippable(HttpServletRequest request) {&lt;br /&gt;
        return SKIPPABLE_PATTERN.matcher(request.getRequestURI()).matches();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isValidRequest(HttpSession session, HttpServletRequest request) {&lt;br /&gt;
        String original = (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
        String now = (String)request.getParameter(OWASP_CSRFTOKEN);&lt;br /&gt;
        boolean result = false;&lt;br /&gt;
        &lt;br /&gt;
        if(now != null &amp;amp;&amp;amp; now.equals(original)) {&lt;br /&gt;
            result = true;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildFormParameters(String content, String token) {&lt;br /&gt;
        return FORM_PATTERN.matcher(content).replaceAll(&amp;quot;&amp;lt;input type=\&amp;quot;hidden\&amp;quot; name=\&amp;quot;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;\&amp;quot; value=\&amp;quot;&amp;quot; + token + &amp;quot;\&amp;quot;&amp;gt;\n&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token) {&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;href=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;src=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token, String pattern, char termChar) {&lt;br /&gt;
        StringBuffer buffer = new StringBuffer();&lt;br /&gt;
        int i=0;&lt;br /&gt;
        int index = 0;&lt;br /&gt;
        int length = content.length();&lt;br /&gt;
        &lt;br /&gt;
        while(i &amp;lt; length) {&lt;br /&gt;
            index = content.toLowerCase().indexOf(pattern, i);&lt;br /&gt;
            &lt;br /&gt;
            if(index != -1) {&lt;br /&gt;
                int offset = 0;&lt;br /&gt;
                int n = 0;&lt;br /&gt;
                boolean parameters = false;&lt;br /&gt;
                String tokenString = null;&lt;br /&gt;
                buffer.append(content.substring(i, index+pattern.length()));&lt;br /&gt;
                &lt;br /&gt;
                for(n=index+pattern.length(), offset=n; n&amp;lt;=length &amp;amp;&amp;amp; content.charAt(n) != termChar; n++) {&lt;br /&gt;
                    buffer.append(content.charAt(n));&lt;br /&gt;
                    &lt;br /&gt;
                    if(content.charAt(n) == '?') {&lt;br /&gt;
                        parameters = true;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                if(parameters) {&lt;br /&gt;
                    tokenString = &amp;quot;&amp;amp;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                } else {&lt;br /&gt;
                    tokenString = &amp;quot;?&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                buffer.append(tokenString);&lt;br /&gt;
                &lt;br /&gt;
                i = index + pattern.length() + (n - offset);&lt;br /&gt;
            } else {&lt;br /&gt;
                buffer.append(content.substring(i, length));&lt;br /&gt;
                &lt;br /&gt;
                i = length;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return buffer.toString();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Download ===&lt;br /&gt;
&lt;br /&gt;
The Proof-of-Concept implementation of the Cross-Site Request Forgery Guard discussed in this article can be downloaded here: [[:Image:CSRF_Guard.zip|CSRF_Guard.zip]]&lt;br /&gt;
&lt;br /&gt;
=== Related Projects ===&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the PHP platform is under development: [[PHP CSRF Guard]]&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the ASP.Net platform (as an ASP.Net Module/Filter) is under development as part of the OWASP .Net project toolset. [[.Net CSRF Guard]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
:* http://news.com.com/Netflix+fixes+Web+2.0+bugs/2100-1002_3-6126438.html?tag=cd.lede&lt;br /&gt;
:* http://shiflett.org/articles/foiling-cross-site-attacks&lt;br /&gt;
:* http://java.sun.com/j2se/1.4.2/docs/api/java/security/SecureRandom.html&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_CSRFGuard_Project]]&lt;br /&gt;
[[Category:OWASP_Validation_Project]]&lt;br /&gt;
[[Category:Countermeasure]]&lt;br /&gt;
[[Category:Java]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=File_talk:CSRFTester-1.0.zip&amp;diff=23526</id>
		<title>File talk:CSRFTester-1.0.zip</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=File_talk:CSRFTester-1.0.zip&amp;diff=23526"/>
				<updated>2007-11-19T04:44:57Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: New page: Any chance that this could be done as a module/plugin within the new OWASP WebScarab NG?  Would be handy to have in one single tool. ~~~~&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Any chance that this could be done as a module/plugin within the new OWASP WebScarab NG?  Would be handy to have in one single tool.&lt;br /&gt;
[[User:Jaxley|Jaxley]] 23:44, 18 November 2007 (EST)&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23507</id>
		<title>CSRF Guard</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23507"/>
				<updated>2007-11-19T00:50:07Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: /* Download */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Just when developers are starting to run in circles over [[Cross Site Scripting]], the [http://www.darkreading.com/document.asp?doc_id=107651&amp;amp;WT.svl=news1_2 'sleeping giant'] awakes for yet another web-catastrophe. [[Cross-Site Request Forgery]] (CSRF) is an attack whereby the victim is tricked into loading information from or submitting information to a web application for which they are currently authenticated. The problem is that the web application has no means of verifying the integrity of the request.&lt;br /&gt;
&lt;br /&gt;
==Recommended Prevention Measure: Unique Request Tokens==&lt;br /&gt;
&lt;br /&gt;
The core issue with CSRF attacks is that form submission can be imitated with forged requests. The application must be able to differentiate between legal requests and forged requests. Since all headers, cookies, and credentials will be submitted with both legal and forged requests, the only method of truly verifying the integrity of the request is with a uniquely identifiable token in the form of an HTTP parameter. When the user first visits the site, the application will generate and store a ''session specific'' unique request token. This session specific unique request token is then placed in each form and link of the HTML response, ensuring that this value will be submitted with the next request. For each subsequent request, the application must verify the existence of the unique token parameter and compare its value to that of the value stored in the user's session. The security of the approach is based on the fact that this unique token value is specific to a user's session and is ''hard to guess.'' Therefore, it is imperative that this value is large and cryptographically secure.&lt;br /&gt;
&lt;br /&gt;
:*'''UPDATE:''' There have been discussions suggesting that the unique request token can be compromised using JavaScript. This attack implies that the application also contains a Cross-Site scripting vulnerability, which is a more severe issue than Cross-Site request forgery. The first Myspace worm worked in this manner where it used a Cross Site Scripting vulnerability to forge requests to update a user's profile, where the user profile update mechanism was protected with an antiCSRF defense mechanism similar to what is provided by this filter. You can mitigate this risk somewhat by making your form key AND value a CSRF Guard-type token.&lt;br /&gt;
&lt;br /&gt;
==Example: The Java CSRF Guard==&lt;br /&gt;
&lt;br /&gt;
=== Java EE Filter ===&lt;br /&gt;
&lt;br /&gt;
Java EE filters provide the ability to intercept, view, and modify both the request and associated response for the requesting client. Filters are inserted and executed by the Java EE container's deployment descriptor (web.xml) file. For example, if an HTTP request for a JSP page hits our Apache web server, the request is sent to Tomcat for processing. Before Tomcat executes the code inside of the JSP, the request must be passed along a chain of Java EE filters. The following snippet illustrates how to declare and map a filter to a particular URI-space in web.xml:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;filter&amp;gt;&lt;br /&gt;
    &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
    &amp;lt;filter-class&amp;gt;org.owasp.csrf.CSRFGuard&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
      &amp;lt;init-param&amp;gt;&lt;br /&gt;
        &amp;lt;param-name&amp;gt;error-page&amp;lt;/param-name&amp;gt;&lt;br /&gt;
        &amp;lt;param-value&amp;gt;error.jsp&amp;lt;/param-value&amp;gt;&lt;br /&gt;
      &amp;lt;/init-param&amp;gt;&lt;br /&gt;
 &amp;lt;/filter&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;
   &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
   &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
 &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Implementing the CSRF Guard as a Java EE Filter gives us the ability to verify the integrity of the request before it ever hits our web application.&lt;br /&gt;
&lt;br /&gt;
=== Secure Random ===&lt;br /&gt;
&lt;br /&gt;
When implementing the CSRF Guard, we must ensure that the unique request token is cryptographically strong. After all, our implementation relies on the principle that the unique token is difficult to guess. If the unique request token can be easily guessed then a CSRF attack can be executed.&lt;br /&gt;
&lt;br /&gt;
The following code snippet generates a BASE64 encoded string of 'size' bytes:&lt;br /&gt;
&lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
&lt;br /&gt;
The following Java EE Filter will attempt to verify the integrity of the request by comparing the OWASP_CSRFTOKEN HTTP parameter value with that of the OWASP_CSRFTOKEN session attribute. If the two values do not match, then the request is forged and we invoked the doError() method. This method will invalidate the existing session and redirect the user to a page specified by the filter init-parameter &amp;quot;error-page&amp;quot;. If the parameter value equals the corresponding session attribute value, then we call doChain() and pass the request to the webapplication. Once the web application is finished processing the request, the buildLinkParameters() method will search the HTML response for forms and links and insert the appropriate OWASP_CSRFTOKEN parameter value. Unfortunately, the dependency on an HTML response means that the current filter may not work with some Web 2.0 applications. Furthermore, the filter only modifies response objects whose &amp;quot;Content-Type&amp;quot; header is text based. If your web application neglects to set the appropriate value for the &amp;quot;Content-Type&amp;quot; header, then the CSRF Guard will not make the appropriate changes to the HTML response and each subsequent request will be considered a violation.&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * CSRFGuard.java&lt;br /&gt;
  *&lt;br /&gt;
  * Created on January 2, 2007, 11:35 AM&lt;br /&gt;
  *&lt;br /&gt;
  * Copyright (C) 2007 Eric Sheridan&lt;br /&gt;
  *&lt;br /&gt;
  * This library is free software; you can redistribute it and/or&lt;br /&gt;
  * modify it under the terms of the GNU Lesser General Public&lt;br /&gt;
  * License as published by the Free Software Foundation; either&lt;br /&gt;
  * version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;
  *&lt;br /&gt;
  * This library is distributed in the hope that it will be useful,&lt;br /&gt;
  * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU&lt;br /&gt;
  * Lesser General Public License for more details.&lt;br /&gt;
  *&lt;br /&gt;
  * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
  * License along with this library; if not, write to the Free Software&lt;br /&gt;
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 package org.owasp.csrf;&lt;br /&gt;
  &lt;br /&gt;
 import java.io.OutputStream;&lt;br /&gt;
 import java.io.IOException;&lt;br /&gt;
 import java.security.SecureRandom;&lt;br /&gt;
 import java.util.regex.Pattern;&lt;br /&gt;
 import javax.servlet.Filter;&lt;br /&gt;
 import javax.servlet.FilterChain;&lt;br /&gt;
 import javax.servlet.FilterConfig;&lt;br /&gt;
 import javax.servlet.ServletException;&lt;br /&gt;
 import javax.servlet.ServletRequest;&lt;br /&gt;
 import javax.servlet.ServletResponse;&lt;br /&gt;
 import javax.servlet.http.HttpSession;&lt;br /&gt;
 import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
 import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
 import sun.misc.BASE64Encoder;&lt;br /&gt;
 import org.owasp.csrf.http.MutableHttpResponse;&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *&lt;br /&gt;
  * @author esheridan&lt;br /&gt;
  */&lt;br /&gt;
 public class CSRFGuard implements Filter {&lt;br /&gt;
    public final static String OWASP_CSRFTOKEN = &amp;quot;OWASP_CSRFTOKEN&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern FORM_PATTERN = Pattern.compile(&amp;quot;(?i)&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern SKIPPABLE_PATTERN = Pattern.compile(&amp;quot;.*\\.(gif|jpg|png|css|js|ico|swf|axd.*)$&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    private String errorPage = null;&lt;br /&gt;
    &lt;br /&gt;
    public void init(FilterConfig config) {&lt;br /&gt;
        errorPage = config.getInitParameter(&amp;quot;error-page&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {&lt;br /&gt;
        if(request instanceof HttpServletRequest &amp;amp;&amp;amp; response instanceof HttpServletResponse) {&lt;br /&gt;
            try {&lt;br /&gt;
                HttpServletRequest hRequest = (HttpServletRequest)request;&lt;br /&gt;
                MutableHttpResponse mResponse = new MutableHttpResponse((HttpServletResponse)response);&lt;br /&gt;
                HttpSession session = hRequest.getSession(false);&lt;br /&gt;
                &lt;br /&gt;
                if(session != null) {&lt;br /&gt;
                    if(!hasCSRFToken(session)) {&lt;br /&gt;
                        setCSRFToken(session);&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else if(isSkippable(hRequest) || isValidRequest(session, hRequest)) {&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else {&lt;br /&gt;
                        doError(session, (HttpServletResponse)response);&lt;br /&gt;
                    }&lt;br /&gt;
                } else {&lt;br /&gt;
                    chain.doFilter(request, response);&lt;br /&gt;
                }&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
                e.printStackTrace();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doError(HttpSession session, HttpServletResponse response) throws IOException {&lt;br /&gt;
        session.invalidate();&lt;br /&gt;
        response.sendRedirect(errorPage);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doChain(HttpServletRequest request, MutableHttpResponse mResponse, ServletResponse response, FilterChain chain) throws IOException, ServletException {&lt;br /&gt;
        OutputStream out = response.getOutputStream();&lt;br /&gt;
        &lt;br /&gt;
        chain.doFilter(request, mResponse);&lt;br /&gt;
        &lt;br /&gt;
        String contentType = mResponse.getContentType();&lt;br /&gt;
        String token = getCSRFToken(request.getSession());&lt;br /&gt;
        &lt;br /&gt;
        if(contentType != null &amp;amp;&amp;amp; contentType.startsWith(&amp;quot;text&amp;quot;)) {&lt;br /&gt;
            String content = new String(mResponse.getContent());&lt;br /&gt;
            content = getModifiedResponse(token, content);&lt;br /&gt;
            byte[] result = content.getBytes();&lt;br /&gt;
            &lt;br /&gt;
            response.setContentLength(result.length);&lt;br /&gt;
            out.write(result);&lt;br /&gt;
        } else {&lt;br /&gt;
            out.write(mResponse.getContent());&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        out.close();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getModifiedResponse(String token, String content) {&lt;br /&gt;
        content = buildFormParameters(content, token);&lt;br /&gt;
        content = buildLinkParameters(content, token);&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getCSRFToken(HttpSession session) {&lt;br /&gt;
        return (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean hasCSRFToken(HttpSession session) {&lt;br /&gt;
        return getCSRFToken(session) != null;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void setCSRFToken(HttpSession session) {&lt;br /&gt;
        session.setAttribute(OWASP_CSRFTOKEN, generateCSRFToken());&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken() {&lt;br /&gt;
        return generateCSRFToken(32);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random).replace('+', '_');&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isSkippable(HttpServletRequest request) {&lt;br /&gt;
        return SKIPPABLE_PATTERN.matcher(request.getRequestURI()).matches();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isValidRequest(HttpSession session, HttpServletRequest request) {&lt;br /&gt;
        String original = (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
        String now = (String)request.getParameter(OWASP_CSRFTOKEN);&lt;br /&gt;
        boolean result = false;&lt;br /&gt;
        &lt;br /&gt;
        if(now != null &amp;amp;&amp;amp; now.equals(original)) {&lt;br /&gt;
            result = true;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildFormParameters(String content, String token) {&lt;br /&gt;
        return FORM_PATTERN.matcher(content).replaceAll(&amp;quot;&amp;lt;input type=\&amp;quot;hidden\&amp;quot; name=\&amp;quot;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;\&amp;quot; value=\&amp;quot;&amp;quot; + token + &amp;quot;\&amp;quot;&amp;gt;\n&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token) {&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;href=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;src=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token, String pattern, char termChar) {&lt;br /&gt;
        StringBuffer buffer = new StringBuffer();&lt;br /&gt;
        int i=0;&lt;br /&gt;
        int index = 0;&lt;br /&gt;
        int length = content.length();&lt;br /&gt;
        &lt;br /&gt;
        while(i &amp;lt; length) {&lt;br /&gt;
            index = content.toLowerCase().indexOf(pattern, i);&lt;br /&gt;
            &lt;br /&gt;
            if(index != -1) {&lt;br /&gt;
                int offset = 0;&lt;br /&gt;
                int n = 0;&lt;br /&gt;
                boolean parameters = false;&lt;br /&gt;
                String tokenString = null;&lt;br /&gt;
                buffer.append(content.substring(i, index+pattern.length()));&lt;br /&gt;
                &lt;br /&gt;
                for(n=index+pattern.length(), offset=n; n&amp;lt;=length &amp;amp;&amp;amp; content.charAt(n) != termChar; n++) {&lt;br /&gt;
                    buffer.append(content.charAt(n));&lt;br /&gt;
                    &lt;br /&gt;
                    if(content.charAt(n) == '?') {&lt;br /&gt;
                        parameters = true;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                if(parameters) {&lt;br /&gt;
                    tokenString = &amp;quot;&amp;amp;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                } else {&lt;br /&gt;
                    tokenString = &amp;quot;?&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                buffer.append(tokenString);&lt;br /&gt;
                &lt;br /&gt;
                i = index + pattern.length() + (n - offset);&lt;br /&gt;
            } else {&lt;br /&gt;
                buffer.append(content.substring(i, length));&lt;br /&gt;
                &lt;br /&gt;
                i = length;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return buffer.toString();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Download ===&lt;br /&gt;
&lt;br /&gt;
The Proof-of-Concept implementation of the Cross-Site Request Forgery Guard discussed in this article can be downloaded [http://www.owasp.org/index.php/Image:CSRF_Guard.zip here]&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the PHP platform is under development [http://www.owasp.org/index.php/PHP_CSRF_Guard here]&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the ASP.Net platform (as an ASP.Net Module/Filter) is under development and will be part of the OWASP .Net project toolset.  Contact [[User:Jaxley|Jaxley]] for details.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
:* http://news.com.com/Netflix+fixes+Web+2.0+bugs/2100-1002_3-6126438.html?tag=cd.lede&lt;br /&gt;
:* http://shiflett.org/articles/foiling-cross-site-attacks&lt;br /&gt;
:* http://java.sun.com/j2se/1.4.2/docs/api/java/security/SecureRandom.html&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Validation_Project]]&lt;br /&gt;
[[Category:Countermeasure]]&lt;br /&gt;
[[Category:Java]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23506</id>
		<title>User:Jaxley</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jaxley&amp;diff=23506"/>
				<updated>2007-11-19T00:37:40Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: New page: == Jason Axley == Seattle, WA&amp;lt;br&amp;gt; http://juxtaposition.axley.net  OWASP .Net Project volunteer  Currently working on or planning these projects:  * OWASP CSRFGuard .Net port (highly functi...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Jason Axley ==&lt;br /&gt;
Seattle, WA&amp;lt;br&amp;gt;&lt;br /&gt;
http://juxtaposition.axley.net&lt;br /&gt;
&lt;br /&gt;
OWASP .Net Project volunteer&lt;br /&gt;
&lt;br /&gt;
Currently working on or planning these projects:&lt;br /&gt;
&lt;br /&gt;
* OWASP CSRFGuard .Net port (highly functional POC in the works; need to document on a wiki page)&lt;br /&gt;
* .Net fuzzer enhancements (BO_Finder)&lt;br /&gt;
* OWASP SiteGenerator spider-&amp;gt;XML to create realistic demo websites you can add vulnerabilities to for testing/training&lt;br /&gt;
* .Net Enterprise Security API / mod_security port enhancements&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23482</id>
		<title>CSRF Guard</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=CSRF_Guard&amp;diff=23482"/>
				<updated>2007-11-16T23:46:19Z</updated>
		
		<summary type="html">&lt;p&gt;Jaxley: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Just when developers are starting to run in circles over [[Cross Site Scripting]], the [http://www.darkreading.com/document.asp?doc_id=107651&amp;amp;WT.svl=news1_2 'sleeping giant'] awakes for yet another web-catastrophe. [[Cross-Site Request Forgery]] (CSRF) is an attack whereby the victim is tricked into loading information from or submitting information to a web application for which they are currently authenticated. The problem is that the web application has no means of verifying the integrity of the request.&lt;br /&gt;
&lt;br /&gt;
==Recommended Prevention Measure: Unique Request Tokens==&lt;br /&gt;
&lt;br /&gt;
The core issue with CSRF attacks is that form submission can be imitated with forged requests. The application must be able to differentiate between legal requests and forged requests. Since all headers, cookies, and credentials will be submitted with both legal and forged requests, the only method of truly verifying the integrity of the request is with a uniquely identifiable token in the form of an HTTP parameter. When the user first visits the site, the application will generate and store a ''session specific'' unique request token. This session specific unique request token is then placed in each form and link of the HTML response, ensuring that this value will be submitted with the next request. For each subsequent request, the application must verify the existence of the unique token parameter and compare its value to that of the value stored in the user's session. The security of the approach is based on the fact that this unique token value is specific to a user's session and is ''hard to guess.'' Therefore, it is imperative that this value is large and cryptographically secure.&lt;br /&gt;
&lt;br /&gt;
:*'''UPDATE:''' There have been discussions suggesting that the unique request token can be compromised using JavaScript. This attack implies that the application also contains a Cross-Site scripting vulnerability, which is a more severe issue than Cross-Site request forgery. The first Myspace worm worked in this manner where it used a Cross Site Scripting vulnerability to forge requests to update a user's profile, where the user profile update mechanism was protected with an antiCSRF defense mechanism similar to what is provided by this filter. You can mitigate this risk somewhat by making your form key AND value a CSRF Guard-type token.&lt;br /&gt;
&lt;br /&gt;
==Example: The Java CSRF Guard==&lt;br /&gt;
&lt;br /&gt;
=== Java EE Filter ===&lt;br /&gt;
&lt;br /&gt;
Java EE filters provide the ability to intercept, view, and modify both the request and associated response for the requesting client. Filters are inserted and executed by the Java EE container's deployment descriptor (web.xml) file. For example, if an HTTP request for a JSP page hits our Apache web server, the request is sent to Tomcat for processing. Before Tomcat executes the code inside of the JSP, the request must be passed along a chain of Java EE filters. The following snippet illustrates how to declare and map a filter to a particular URI-space in web.xml:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;filter&amp;gt;&lt;br /&gt;
    &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
    &amp;lt;filter-class&amp;gt;org.owasp.csrf.CSRFGuard&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
      &amp;lt;init-param&amp;gt;&lt;br /&gt;
        &amp;lt;param-name&amp;gt;error-page&amp;lt;/param-name&amp;gt;&lt;br /&gt;
        &amp;lt;param-value&amp;gt;error.jsp&amp;lt;/param-value&amp;gt;&lt;br /&gt;
      &amp;lt;/init-param&amp;gt;&lt;br /&gt;
 &amp;lt;/filter&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;
   &amp;lt;filter-name&amp;gt;CSRFGuard&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
   &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
 &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Implementing the CSRF Guard as a Java EE Filter gives us the ability to verify the integrity of the request before it ever hits our web application.&lt;br /&gt;
&lt;br /&gt;
=== Secure Random ===&lt;br /&gt;
&lt;br /&gt;
When implementing the CSRF Guard, we must ensure that the unique request token is cryptographically strong. After all, our implementation relies on the principle that the unique token is difficult to guess. If the unique request token can be easily guessed then a CSRF attack can be executed.&lt;br /&gt;
&lt;br /&gt;
The following code snippet generates a BASE64 encoded string of 'size' bytes:&lt;br /&gt;
&lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
&lt;br /&gt;
The following Java EE Filter will attempt to verify the integrity of the request by comparing the OWASP_CSRFTOKEN HTTP parameter value with that of the OWASP_CSRFTOKEN session attribute. If the two values do not match, then the request is forged and we invoked the doError() method. This method will invalidate the existing session and redirect the user to a page specified by the filter init-parameter &amp;quot;error-page&amp;quot;. If the parameter value equals the corresponding session attribute value, then we call doChain() and pass the request to the webapplication. Once the web application is finished processing the request, the buildLinkParameters() method will search the HTML response for forms and links and insert the appropriate OWASP_CSRFTOKEN parameter value. Unfortunately, the dependency on an HTML response means that the current filter may not work with some Web 2.0 applications. Furthermore, the filter only modifies response objects whose &amp;quot;Content-Type&amp;quot; header is text based. If your web application neglects to set the appropriate value for the &amp;quot;Content-Type&amp;quot; header, then the CSRF Guard will not make the appropriate changes to the HTML response and each subsequent request will be considered a violation.&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * CSRFGuard.java&lt;br /&gt;
  *&lt;br /&gt;
  * Created on January 2, 2007, 11:35 AM&lt;br /&gt;
  *&lt;br /&gt;
  * Copyright (C) 2007 Eric Sheridan&lt;br /&gt;
  *&lt;br /&gt;
  * This library is free software; you can redistribute it and/or&lt;br /&gt;
  * modify it under the terms of the GNU Lesser General Public&lt;br /&gt;
  * License as published by the Free Software Foundation; either&lt;br /&gt;
  * version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;
  *&lt;br /&gt;
  * This library is distributed in the hope that it will be useful,&lt;br /&gt;
  * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU&lt;br /&gt;
  * Lesser General Public License for more details.&lt;br /&gt;
  *&lt;br /&gt;
  * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
  * License along with this library; if not, write to the Free Software&lt;br /&gt;
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 package org.owasp.csrf;&lt;br /&gt;
  &lt;br /&gt;
 import java.io.OutputStream;&lt;br /&gt;
 import java.io.IOException;&lt;br /&gt;
 import java.security.SecureRandom;&lt;br /&gt;
 import java.util.regex.Pattern;&lt;br /&gt;
 import javax.servlet.Filter;&lt;br /&gt;
 import javax.servlet.FilterChain;&lt;br /&gt;
 import javax.servlet.FilterConfig;&lt;br /&gt;
 import javax.servlet.ServletException;&lt;br /&gt;
 import javax.servlet.ServletRequest;&lt;br /&gt;
 import javax.servlet.ServletResponse;&lt;br /&gt;
 import javax.servlet.http.HttpSession;&lt;br /&gt;
 import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
 import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
 import sun.misc.BASE64Encoder;&lt;br /&gt;
 import org.owasp.csrf.http.MutableHttpResponse;&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *&lt;br /&gt;
  * @author esheridan&lt;br /&gt;
  */&lt;br /&gt;
 public class CSRFGuard implements Filter {&lt;br /&gt;
    public final static String OWASP_CSRFTOKEN = &amp;quot;OWASP_CSRFTOKEN&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern FORM_PATTERN = Pattern.compile(&amp;quot;(?i)&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    public final static Pattern SKIPPABLE_PATTERN = Pattern.compile(&amp;quot;.*\\.(gif|jpg|png|css|js|ico|swf|axd.*)$&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    private String errorPage = null;&lt;br /&gt;
    &lt;br /&gt;
    public void init(FilterConfig config) {&lt;br /&gt;
        errorPage = config.getInitParameter(&amp;quot;error-page&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {&lt;br /&gt;
        if(request instanceof HttpServletRequest &amp;amp;&amp;amp; response instanceof HttpServletResponse) {&lt;br /&gt;
            try {&lt;br /&gt;
                HttpServletRequest hRequest = (HttpServletRequest)request;&lt;br /&gt;
                MutableHttpResponse mResponse = new MutableHttpResponse((HttpServletResponse)response);&lt;br /&gt;
                HttpSession session = hRequest.getSession(false);&lt;br /&gt;
                &lt;br /&gt;
                if(session != null) {&lt;br /&gt;
                    if(!hasCSRFToken(session)) {&lt;br /&gt;
                        setCSRFToken(session);&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else if(isSkippable(hRequest) || isValidRequest(session, hRequest)) {&lt;br /&gt;
                        doChain(hRequest, mResponse, response, chain);&lt;br /&gt;
                    } else {&lt;br /&gt;
                        doError(session, (HttpServletResponse)response);&lt;br /&gt;
                    }&lt;br /&gt;
                } else {&lt;br /&gt;
                    chain.doFilter(request, response);&lt;br /&gt;
                }&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
                e.printStackTrace();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doError(HttpSession session, HttpServletResponse response) throws IOException {&lt;br /&gt;
        session.invalidate();&lt;br /&gt;
        response.sendRedirect(errorPage);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void doChain(HttpServletRequest request, MutableHttpResponse mResponse, ServletResponse response, FilterChain chain) throws IOException, ServletException {&lt;br /&gt;
        OutputStream out = response.getOutputStream();&lt;br /&gt;
        &lt;br /&gt;
        chain.doFilter(request, mResponse);&lt;br /&gt;
        &lt;br /&gt;
        String contentType = mResponse.getContentType();&lt;br /&gt;
        String token = getCSRFToken(request.getSession());&lt;br /&gt;
        &lt;br /&gt;
        if(contentType != null &amp;amp;&amp;amp; contentType.startsWith(&amp;quot;text&amp;quot;)) {&lt;br /&gt;
            String content = new String(mResponse.getContent());&lt;br /&gt;
            content = getModifiedResponse(token, content);&lt;br /&gt;
            byte[] result = content.getBytes();&lt;br /&gt;
            &lt;br /&gt;
            response.setContentLength(result.length);&lt;br /&gt;
            out.write(result);&lt;br /&gt;
        } else {&lt;br /&gt;
            out.write(mResponse.getContent());&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        out.close();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getModifiedResponse(String token, String content) {&lt;br /&gt;
        content = buildFormParameters(content, token);&lt;br /&gt;
        content = buildLinkParameters(content, token);&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String getCSRFToken(HttpSession session) {&lt;br /&gt;
        return (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean hasCSRFToken(HttpSession session) {&lt;br /&gt;
        return getCSRFToken(session) != null;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void setCSRFToken(HttpSession session) {&lt;br /&gt;
        session.setAttribute(OWASP_CSRFTOKEN, generateCSRFToken());&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken() {&lt;br /&gt;
        return generateCSRFToken(32);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String generateCSRFToken(int size) {&lt;br /&gt;
        SecureRandom sr = null;&lt;br /&gt;
        byte[] random = new byte[size];&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        String digest = null;&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            sr = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
            &lt;br /&gt;
            sr.nextBytes(random);&lt;br /&gt;
            &lt;br /&gt;
            digest = encoder.encode(random).replace('+', '_');&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return digest;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isSkippable(HttpServletRequest request) {&lt;br /&gt;
        return SKIPPABLE_PATTERN.matcher(request.getRequestURI()).matches();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private boolean isValidRequest(HttpSession session, HttpServletRequest request) {&lt;br /&gt;
        String original = (String)session.getAttribute(OWASP_CSRFTOKEN);&lt;br /&gt;
        String now = (String)request.getParameter(OWASP_CSRFTOKEN);&lt;br /&gt;
        boolean result = false;&lt;br /&gt;
        &lt;br /&gt;
        if(now != null &amp;amp;&amp;amp; now.equals(original)) {&lt;br /&gt;
            result = true;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildFormParameters(String content, String token) {&lt;br /&gt;
        return FORM_PATTERN.matcher(content).replaceAll(&amp;quot;&amp;lt;input type=\&amp;quot;hidden\&amp;quot; name=\&amp;quot;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;\&amp;quot; value=\&amp;quot;&amp;quot; + token + &amp;quot;\&amp;quot;&amp;gt;\n&amp;lt;/form&amp;gt;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token) {&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;href=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        content = buildLinkParameters(content, token, &amp;quot;src=\&amp;quot;&amp;quot;, '&amp;quot;');&lt;br /&gt;
        &lt;br /&gt;
        return content;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private String buildLinkParameters(String content, String token, String pattern, char termChar) {&lt;br /&gt;
        StringBuffer buffer = new StringBuffer();&lt;br /&gt;
        int i=0;&lt;br /&gt;
        int index = 0;&lt;br /&gt;
        int length = content.length();&lt;br /&gt;
        &lt;br /&gt;
        while(i &amp;lt; length) {&lt;br /&gt;
            index = content.toLowerCase().indexOf(pattern, i);&lt;br /&gt;
            &lt;br /&gt;
            if(index != -1) {&lt;br /&gt;
                int offset = 0;&lt;br /&gt;
                int n = 0;&lt;br /&gt;
                boolean parameters = false;&lt;br /&gt;
                String tokenString = null;&lt;br /&gt;
                buffer.append(content.substring(i, index+pattern.length()));&lt;br /&gt;
                &lt;br /&gt;
                for(n=index+pattern.length(), offset=n; n&amp;lt;=length &amp;amp;&amp;amp; content.charAt(n) != termChar; n++) {&lt;br /&gt;
                    buffer.append(content.charAt(n));&lt;br /&gt;
                    &lt;br /&gt;
                    if(content.charAt(n) == '?') {&lt;br /&gt;
                        parameters = true;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                if(parameters) {&lt;br /&gt;
                    tokenString = &amp;quot;&amp;amp;&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                } else {&lt;br /&gt;
                    tokenString = &amp;quot;?&amp;quot; + OWASP_CSRFTOKEN + &amp;quot;=&amp;quot; + token;&lt;br /&gt;
                }&lt;br /&gt;
                &lt;br /&gt;
                buffer.append(tokenString);&lt;br /&gt;
                &lt;br /&gt;
                i = index + pattern.length() + (n - offset);&lt;br /&gt;
            } else {&lt;br /&gt;
                buffer.append(content.substring(i, length));&lt;br /&gt;
                &lt;br /&gt;
                i = length;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return buffer.toString();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Download ===&lt;br /&gt;
&lt;br /&gt;
The Proof-of-Concept implementation of the Cross-Site Request Forgery Guard discussed in this article can be downloaded [http://www.owasp.org/index.php/Image:CSRF_Guard.zip here]&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the PHP platform is under development [http://www.owasp.org/index.php/PHP_CSRF_Guard here]&lt;br /&gt;
&lt;br /&gt;
A Proof-of-Concept implementation of the CSRF Guard for the ASP.Net platform (as an ASP.Net Module/Filter) is under development and will be part of the OWASP .Net project toolset.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
:* http://news.com.com/Netflix+fixes+Web+2.0+bugs/2100-1002_3-6126438.html?tag=cd.lede&lt;br /&gt;
:* http://shiflett.org/articles/foiling-cross-site-attacks&lt;br /&gt;
:* http://java.sun.com/j2se/1.4.2/docs/api/java/security/SecureRandom.html&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Validation_Project]]&lt;br /&gt;
[[Category:Countermeasure]]&lt;br /&gt;
[[Category:Java]]&lt;/div&gt;</summary>
		<author><name>Jaxley</name></author>	</entry>

	</feed>