Home » .Net FrameworkRSS

RSA crypto provider on compact framework 2.0 SP2 : Unknown exception when signing with sign key type

The RSA crypto provider on compact framework 2.0 SP2 is throwing an unknown exception when signing with sign key type. The full framework works fine.

Using an exchange key it works fine on both framework.

 

string message = "Tous les chats sont gris la nuit.";

 

            RSACryptoServiceProvider.UseMachineKeyStore = true;

            RSACryptoServiceProvider rsaCryptoServiceProvider = null;

 

            CspParameters parameters = newCspParameters();

            parameters.KeyContainerName = "TEST";

            parameters.KeyNumber = 2; //2 = forSignature; 1 = forExchanging

            parameters.Flags = CspProviderFlags.UseMachineKeyStore;

 

            try

            {

                rsaCryptoServiceProvider = newRSACryptoServiceProvider(parameters);

 

                rsaCryptoServiceProvider.PersistKeyInCsp = true;

 

                byte[] data = Encoding.UTF8.GetBytes(message);

                HashAlgorithm hasher = SHA1.Create(); // Our chosen hashing algorithm.

 

                // when the parameters.KeyNumber has forSignature value, I receive this

                // error : System.Security.Cryptography.CryptographicException was unhandled

                // Message="Unknown Error '80007015'."

                byte[] signedHash = rsaCryptoServiceProvider.SignData(data, hasher);

               

                returnConvert.ToBase64String(signedHash);

 

            }

            finally

            {

                if (rsaCryptoServiceProvider != null)

                    //remove it (we don't want garbage in our machine) this operation is performed

                    //  only for testing purpose.

                    rsaCryptoServiceProvider.PersistKeyInCsp = false;

                    rsaCryptoServiceProvider.Clear();

            }

 

 

Thanks for your help.

 

1 Answer Found

 

Answer 1

Is this happening with Windows Vista or Seven? or with Windows XP?

If the problem is happening with Vista or Seven, this post and the following codeplex proyect will help you:

http://blogs.msdn.com/b/alejacma/archive/2009/12/22/invalid-provider-type-specified-error-when-accessing-x509certificate2-privatekey.aspx

http://clrsecurity.codeplex.com/

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter