This project has moved and is read-only. For the latest updates, please go here.

[Solved] Create CNG Keys

May 3, 2012 at 7:38 AM
Edited May 3, 2012 at 7:48 AM


I have been able to create a CNG Key with this, even gone as far as manipulating some of the parameters... Now only need to be able to specify the key length, which I have not been able to do... Below is a snippet that generates a new key with the details I want, except the setting the key size... I tried adding as a parameter but get an exception.


CngKeyCreationParameters cngParams = new CngKeyCreationParameters(); 
cngParams.KeyUsage = CngKeyUsages.Decryption; 
cngParams.Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider; 
//Throws unsupported exception 
//cngParams.Parameters.Add(new CngProperty("KeySize", new System.Text.UTF8Encoding().GetBytes("2048"),CngPropertyOptions.Persist));
key = CngKey.Create(CngAlgorithm2.Rsa, keyName, cngParams);
May 3, 2012 at 7:48 AM
Edited May 3, 2012 at 7:49 AM

[SOLVED] Posting for other for the benefit of others. Change the original posting's line #5 to:

cngParams.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(2048), CngPropertyOptions.None));

Will write a blog about it on my TechNet blog later.