Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance RSA.Create #17344

Closed
bartonjs opened this issue May 19, 2016 · 9 comments
Closed

Enhance RSA.Create #17344

bartonjs opened this issue May 19, 2016 · 9 comments
Labels
api-approved API was approved in API review, it can be implemented area-System.Security help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@bartonjs
Copy link
Member

During the API review of #16960 it was decided that to enable better cross-plat authoring we should have Create() methods on the following crypto base classes:
ECDsa: Create(), Create(ECCurve), Create(ECParameters)
RSA: Create(), Create(int), Create(RSAParameters)
ECDiffieHellman: Create(), Create(ECCurve), Create(ECParameters)
DSA: Create(), Create(int), Create(DSAParameters)

Hopefully all of these make it for net463, and we should have them in .NET Core as well.

This specific issue tracks adding the int and RSAParameters create overloads for RSA, and is an offshoot of #17266.

@bartonjs
Copy link
Member Author

(Marked as api-approved since this is an action item which came out of the EC import/export design discussion)

@danmoseley
Copy link
Member

Removing NS2.0 label as this isn't in desktop yet

@karelz
Copy link
Member

karelz commented Nov 16, 2016

Should be fairly simple to implement (10 mins + adding new API) - up for grabs.

@leastprivilege
Copy link

So the x-plat problem still exists in netstandard 2.0

RSA.Create will create a 1k key on .NET Framework 4.6.1 and a 2k key on .NET Core 2.

Is there a workaround for that that doesn't involve multi-targeting our library (because of 1 API)? Am I missing something?

@bartonjs
Copy link
Member Author

@leastprivilege

private static RSA CreateRSA(int keySize)
{
    RSA rsa = RSA.Create();

    if (rsa is RSACryptoServiceProvider)
    {
        rsa.Dispose();
        return new RSACng(keySize);
    }

    rsa.KeySize = keySize;
    return rsa;
}

Or

static YourClass()
{
    using (RSA rsa = RSA.Create())
    {
        if (rsa is RSACryptoServiceProvider)
        {
            CryptoConfig.AddAlgorithm(typeof(RSACng), "System.Security.Cryptography.RSA");
        }
    }
}

Though the latter is harmful to code that does blind casting.

@leastprivilege
Copy link

Thanks - but where do I find RSACng ?

According to this
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacng?view=netstandard-2.0

It is not supported by netstandard2 libs.

@leastprivilege
Copy link

nevermind - I think I found it.

@leastprivilege
Copy link

Thanks! It is working!

@rosdi
Copy link

rosdi commented Apr 7, 2018

For those like me, RSACng is available as nuget package. There seems some issue in Visual Studio not able to install this package properly in my project. I had to remove the package, delete bin and obj folder, rebuild and it finally works.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Security help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

7 participants