Home All Groups Group Topic Archive Search About

RSACryptoServiceProvider

Author
6 Sep 2006 11:02 PM
SvenAke
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?

Author
13 Sep 2006 9:07 PM
Joseph Bittman MVP MCSD
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/
<Sven***@gmail.com> wrote in message
Show quoteHide quote
news:1157583752.437821.185540@m73g2000cwd.googlegroups.com...
> 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?
>
Author
15 Sep 2006 8:51 AM
SvenAke@gmail.com
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:
Show quoteHide quote
> 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/
> <Sven***@gmail.com> wrote in message
> news:1157583752.437821.185540@m73g2000cwd.googlegroups.com...
> > 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?
> >
Author
24 Sep 2006 4:20 AM
Joseph Bittman MVP MCSD
Sept. 23, 2006

Hey - sorry for the delayed response....

  It is going to be a very very long post if I wrote out how to do it
securely :-).... check out my CAS blog entries (the bottom ones on this
page):

http://cactidevelopers.resdev.net/Product%20Guides/ProductBlog.aspx?GuideID=66dcc35e-340a-18b0-69c8-45ed4f806c7e

This will help give you an idea of what you are up-against... and what to
research more.

Basically, you are going to have to move your code or change your CAS policy
or something to get greater permissions...... There are some really good
articles on MSDN, however, CAS is something which is very huge... so I'd say
grab 50 cups of coffee and be armed with many evenings of time :-).

Good luck! (Using this from ASP.Net means you'll have even bigger
problems.......)
--

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

Blog/Web Site: http://CactiDevelopers.ResDev.Net/
<Sven***@gmail.com> wrote in message
Show quoteHide quote
news:1158310260.312713.322910@e3g2000cwe.googlegroups.com...
> 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/
>> <Sven***@gmail.com> wrote in message
>> news:1157583752.437821.185540@m73g2000cwd.googlegroups.com...
>> > 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?
>> >
>