This How To includes the following steps:
Create the EncryptionPermission class.
Create the EncryptionPermissionAttribute class.
Install the Permission assembly in the global assembly cache (GAC).
Update the DPAPI managed wrapper code.
Call DPAPI from a medium trust Web application.
The EncryptionPermission class is the custom permission implementation used to authorize access to the unmanaged DPAPI functionality.
▸ To create the CustomPermission class
Create a new Visual C#™ development tool Class Library project CustomPermission, and rename class1.cs to EncryptionPermission.cs.
Add a strong name to the assembly so that you can install it in the GAC. Use the following attribute in assemblyinfo.cs ...