none
System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.

    Question

  • I Used the Example given at

    http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.encrypt.aspx

    with the digital signatures already issued by the trusted third party and got the error stated
    System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.
    at the line of encryption. but this error is not included in the above description.
    sample of my code is:

    RSAParameters
    RSAKeyInfo = new RSAParameters();

    RSAKeyInfo.Modulus =(byte[]) modulus.Clone(); // md

    RSAKeyInfo.Exponent = (byte[])exponent.Clone(); // exp

    RSACryptoServiceProvider oRSA = new RSACryptoServiceProvider();

    oRSA.ImportParameters(RSAKeyInfo);

    //Now secret key is encrypted with cert Pub key

    byte[] EncKey;

    EncKey = oRSA.Encrypt(Rin.Key, false );//line where error generated

    If any one knows the solution please help i searched for this Exception but nothing worked well.


    Thanks and Regards
    Meetu Choudhary
    Wednesday, May 13, 2009 11:53 AM

All replies