Skip to content

Commit

Permalink
Update CNGHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
houseofcat committed Mar 16, 2023
1 parent a02b876 commit 8127aa7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/HouseofCat.Encryption.Providers/CNGHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class CNGHelper
/// <param name="rsaKeyContainerName"></param>
/// <returns>RSACng</returns>
[SupportedOSPlatform("windows")]
public static RSACng GetOrCreateRSACng(string rsaKeyContainerName, int keySize = 4096)
public static RSACng GetOrCreateEphemeralRSACng(string rsaKeyContainerName, int keySize = 4096, CngProvider provider = null)
{
Guard.AgainstNullOrEmpty(rsaKeyContainerName, nameof(rsaKeyContainerName));
if (keySize != 2048 || keySize != 4096) throw new ArgumentOutOfRangeException("Keysize can only be 2048 or 4096.");
Expand All @@ -37,10 +37,14 @@ public static RSACng GetOrCreateRSACng(string rsaKeyContainerName, int keySize =
CngExportPolicies.AllowPlaintextExport
| CngExportPolicies.AllowExport
| CngExportPolicies.AllowArchiving
| CngExportPolicies.AllowPlaintextArchiving,
Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider
| CngExportPolicies.AllowPlaintextArchiving
};

if (provider != null)
{
cngKeyCreationParameters.Provider = provider;
}

cngKey = CngKey.Create(CngAlgorithm.Rsa, rsaKeyContainerName, cngKeyCreationParameters);
}

Expand Down

0 comments on commit 8127aa7

Please sign in to comment.