web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

System.Security.Permissions.KeyContainerPermission, mscorlib Plugin Error

(0) ShareShare
ReportReport
Posted on by

Hi,

I am doing encryption using a public key(Working fine in the plugin)  and decryption using private which is working in a Console app but not working in the plugin. getting below error.

Error : System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.KeyContainerPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Security.Cryptography.Utils.ImportCspBlobHelper(CspAlgorithmType keyType, Byte[] keyBlob, Boolean publicOnly, CspParameters& parameters, Boolean randomKeyContainer, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.ImportCspBlob(Byte[] keyBlob)
at BeatPlan.Plugins.PluginBase.Decrypt(Byte[] encryptedBytes, ITracingService log)
at BeatPlan.Plugins.PluginBase.LicenseValidation(IOrganizationService service, ITracingService log)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.KeyContainerPermission
The Zone of the assembly that failed was:
MyComputer

*This post is locked for comments

I have the same question (0)
  • Radu Chiribelea Profile Picture
    6,667 on at

    What type of plug-in is this - sandboxed or with no isolation?

  • Community Member Profile Picture
    on at

    Hi Radu,

    Isolation mode is sandbox and assembly location is Database.

    Thanks

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Ziya,

    In that case i think this might be a limitation of the sandbox service.

    See similar threads:

    stackoverflow.com/.../39449596

    stackoverflow.com/.../39449596

    Can you share your code for following method: BeatPlan.Plugins.PluginBase.Decrypt(Byte[] encryptedBytes, ITracingService log)

    Regards,

    Radu

  • Community Member Profile Picture
    on at

    HI Radu,

    Below is the code

    public string Decrypt(byte[] encryptedBytes, ITracingService log)

           {

    string privateKey = "BwIAAACkAABSU0EyAAQAAAEAAQC1sapAC+mYA=";

               CspParameters cspParams = new CspParameters { ProviderType = 1 };

               RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(cspParams);

               rsaProvider.ImportCspBlob(Convert.FromBase64String(privateKey));

               byte[] plainBytes = rsaProvider.Decrypt(encryptedBytes, false);

               string plainText = Encoding.UTF8.GetString(plainBytes, 0, plainBytes.Length);

               return plainText;

    }

    Regards

    Ziya

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    I am pretty sure you are trying to access something that you are not allowed to in a Sandboxed plug-in - see community.dynamics.com/.../145118

    If you are using CRM OnPrem you can try to register your plug-in using Isolation Mode = None and see if that works for your. If you are using CRM Online than that won't be an option i'm afraid

    Also your exception offers another hint

    The Zone of the assembly that failed was:
    MyComputer

    The plug-in is trying to load something from the disk and that is not allowed in a Sandbox Plug-in. If you can't change the isolation mode I think you need to find another way to achieve this (and keep using the .NET Base Classes)

    If you don't need this to be done as part of a Sync Operation you can consider also externalizing this feature to an Azure WebJob or Function.

    Hope this helps

    Radu

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans