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 807Step 1. Create the EncryptionPermission ClassThe EncryptionPermission class is the custom permission implementation used toauthorize access to the unmanaged DPAPI functionality. To create the CustomPermission class1. Create a new Visual C# TM development tool Class Library projectCustomPermission, <strong>and</strong> rename class1.cs to EncryptionPermission.cs.2. Add a strong name to the assembly so that you can install it in the GAC. Use thefollowing attribute in assemblyinfo.cs:[assembly: AssemblyKeyFile(@"..\..\CustomPermissions.snk")]3. Use a fixed assembly version.[assembly: AssemblyVersion("1.0.0.1")]4. Add the following using statements to the top of EncryptionPermission.cs.using System.<strong>Security</strong>;using System.<strong>Security</strong>.Permissions;5. Add the following enumerated types to the CustomPermissions namespace.[Flags, Serializable]public enum EncryptionPermissionFlag{Encrypt = 0x01, Decrypt = 0x02}[Flags, Serializable]public enum StorePermissionFlag{User = 0x01, Machine = 0x02}6. Add serialization support to the EncryptionPermission class with the[Serializable] attribute, <strong>and</strong> derive it from CodeAccess<strong>Security</strong> <strong>and</strong>IUnrestrictedPermission. Also, seal the class, as the following shows.[Serializable]public sealed class EncryptionPermission : CodeAccessPermission,IUnrestrictedPermission7. Add two private member variables to maintain the permission state.private EncryptionPermissionFlag _permFlag;private StorePermissionFlag _storePermFlag;

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

Saved successfully!

Ooh no, something went wrong!