11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

820 <strong>Improving</strong> <strong>Web</strong> <strong>Application</strong> <strong>Security</strong>: <strong>Threats</strong> <strong>and</strong> Countermeasures To create a test <strong>Web</strong> application1. Add a new C# ASP.NET <strong>Web</strong> application project to your current solution.2. Add a reference to the Dataprotection.dll assembly.3. Add the following fields to <strong>Web</strong>form1.aspx.●●●●●An input field for the data to encrypt. Use the ID txtDataToEncrypt.A field for the encrypted data. Use the ID txtEncryptedData.A field for the decrypted data. Use the ID txtDecryptedData.An Encrypt button. Use the ID btnEncrypt.A Decrypt button. Use the ID btnDecrypt.● A label for an error message. Use the ID lblError.4. Add the following using statement to the top of <strong>Web</strong>Form1.aspx.cs beneath theexisting using statements.using DataProtection;5. Add the following code for the Encrypt button-click event h<strong>and</strong>ler.private void btnEncrypt_Click(object sender, System.EventArgs e){DataProtector dp = new DataProtector(DataProtector.Store.USE_MACHINE_STORE );try{byte[] dataToEncrypt = Encoding.ASCII.GetBytes(txtDataToEncrypt.Text);// Not passing optional entropy in this example// Could pass r<strong>and</strong>om value (stored by the application) for added security// when using DPAPI with the machine store.txtEncryptedData.Text =Convert.ToBase64String(dp.Encrypt(dataToEncrypt,null));}catch(Exception ex){lblError.ForeColor = Color.Red;lblError.Text = "Exception." + ex.Message;return;}lblError.Text = "";}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!