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.

How To: Create a Custom Encryption Permission 8195. Add the following finally block to the outer try block in the Encrypt method.finally{CodeAccessPermission.RevertAssert();}6. Locate the Decrypt method in dataprotection.cs, <strong>and</strong> add the following code atthe top of the outer try block.StorePermissionFlag storeFlag;if(Store.USE_MACHINE_STORE == store){storeFlag = StorePermissionFlag.Machine;}else{storeFlag = StorePermissionFlag.User;}// Dem<strong>and</strong> custom EncryptionPermission.(new EncryptionPermission(EncryptionPermissionFlag.Decrypt, storeFlag)).Dem<strong>and</strong>();// Assert the unmanaged code permission.(new <strong>Security</strong>Permission(<strong>Security</strong>PermissionFlag.UnmanagedCode)).Assert();7. Add the following finally block to the outer try block in the Decrypt method.finally{CodeAccessPermission.RevertAssert();}Step 5. Call DPAPI from a Medium Trust <strong>Web</strong> <strong>Application</strong>To use the DPAPI managed wrapper from a medium trust <strong>Web</strong> application or anypartial trust code, you must configure code access security policy to grant the codethe custom EncryptionPermission.In this step, you create a test <strong>Web</strong> application <strong>and</strong> then modify ASP.NET codeaccess security policy for a medium trust <strong>Web</strong> application to grant it theEncryptionPermission.

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

Saved successfully!

Ooh no, something went wrong!