none
CSharpCodeProvider can not find strong names key container RRS feed

  • Question

  • Hi,

    I am creating strong name signing key with code like this:

     

    string privateKey = "My private key XML here...";
    CspParameters rsaParams = new CspParameters();
    rsaParams.KeyContainerName = "Strong Name Key";
    rsaParams.ProviderName = "Microsoft Strong Cryptographic Provider";
    rsaParams.ProviderType = 1;
    rsa = new RSACryptoServiceProvider(rsaParams);
    rsa.PersistKeyInCsp = true;
    rsa.FromXmlString(privateKey);
    rsa.Clear();
    CompilerParameters cParams = new CompilerParameters();
    cParams.CompilerOptions = "/keycontainer:\"Strong Name Key\"";
    

     I got following error from C# compiler when i try to compile C# code dinamically:

    The key container name 'Strong Name Key' does not exist

    However, this key definitelly exists!!! (I create it with code above, and I can access this key container when i create RSA instances).

    What is bug cause? Where does C# compiler searches for key containers?

    Thursday, July 29, 2010 4:11 PM

Answers

  • Hi,

    no, RSA.Clear() has not to remove key automatically if key is marked as persistent.

    I found solution. The problem is that compiler users ENCRYPTION key instead of SIGNATURE key to sign code. It is really strange that compiler developers implement signing in such a way.

    However, my error is that I marked key as "AT_SIGNATURE" (well, we plan to sign code, so key must be for signature, yes?)

    But CSC expects that key is "AT_KEYEXCHANGE", and this fact is not documented.

    • Marked as answer by VASoftOnline Wednesday, August 18, 2010 12:07 PM
    Wednesday, August 18, 2010 12:07 PM

All replies

  • Hi,

      Thanks for your post. I am not an expert on crypto service. According to MSDN, RSACryptoServiceProvider derives from RSA type, and RSA type derives from AsymmetricAlgorithm RSACryptoServiceProvider.Clear() method releases all resources used by the AsymmetricAlgorithm class. I would suggest you check this out.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Edited by SamAgain Tuesday, August 3, 2010 10:44 AM refine
    • Marked as answer by SamAgain Friday, August 6, 2010 5:15 AM
    • Unmarked as answer by VASoftOnline Wednesday, August 18, 2010 12:00 PM
    Tuesday, August 3, 2010 10:39 AM
  • We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Please mark the right answer at right time.
    Thanks,
    Sam
    Friday, August 6, 2010 5:15 AM
  • Hi,

    no, RSA.Clear() has not to remove key automatically if key is marked as persistent.

    I found solution. The problem is that compiler users ENCRYPTION key instead of SIGNATURE key to sign code. It is really strange that compiler developers implement signing in such a way.

    However, my error is that I marked key as "AT_SIGNATURE" (well, we plan to sign code, so key must be for signature, yes?)

    But CSC expects that key is "AT_KEYEXCHANGE", and this fact is not documented.

    • Marked as answer by VASoftOnline Wednesday, August 18, 2010 12:07 PM
    Wednesday, August 18, 2010 12:07 PM