Re: RSACryptoServiceProvider



Ok!

I'm new to this ASP.NET stuff - so, how do I grant the application more
permissions - it's a "code-behind" ASP thingy so I can't use the
snap-in or...

Rgrds

Joseph Bittman MVP MCSD wrote:
Sept. 13, 2006

That error message probably means your code doesn't have the Code Access
Security permissions required to read the private key... check out the .Net
Framework 2.0 Config snapin to evaluate your assembly to see which
permissions you get granted, and whether you need to grant your code more
security permissions.

This is the permission you need for your code:
System.Security.Permissions.KeyContainerPermission



--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://CactiDevelopers.ResDev.Net/
<SvenAke@xxxxxxxxx> wrote in message
news:1157583752.437821.185540@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying this out usig ASP 2.0.
The public key part works ok but the private key request fails.

CspParameters cspParams = new CspParameters();
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider rsa = new
RSACryptoServiceProvider(cspParams);
rsa.PersistKeyInCsp = false;
string publickey = rsa.ToXmlString(false);
string privatekey = rsa.ToXmlString(true);



[SecurityException: Request for the permission of type
'System.Security.Permissions.KeyContainerPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +59

System.Security.Cryptography.RSACryptoServiceProvider.ExportParameters(Boolean
includePrivateParameters) +120
System.Security.Cryptography.RSA.ToXmlString(Boolean
includePrivateParameters) +41
_Default.Button2_Click(Object sender, EventArgs e) +112
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+6953
System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+154
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
+18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.license_aspx.ProcessRequest(HttpContext context) in
App_Web_4boqwxxn.0.cs:0

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+154
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +64


Any leads?


.


Quantcast