Key versions do not match between encrypted key and decryption algorithm

Topics: Cryptography Application Block, Security Application Block
Mar 7, 2007 at 5:07 PM
Have you ever migrated some project from EntLib 1.1 to 2.0?

I'm migrating Cryptography module; I exported key (RijndaelManaged) by "EntLib Configuration 1.1" and imported by "EntLib Configuration 2.0". The problem is that I'm getting this message that don't let me use that key:

System.InvalidOperationException: Key versions do not match between encrypted key and decryption algorithm
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.KeyReaderWriter.Restore(Stream protectedKeyStream, String passphrase)
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.KeyReaderWriter.Restore(Stream protectedKeyStream, String passphrase, DataProtectionScope protectionScope)
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.KeyManager.RestoreKey(Stream inputStream, String passphrase, DataProtectionScope protectionScope)
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.Design.CryptographicKeyWizard.btnFinish_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Mar 12, 2007 at 3:43 PM
I haven't migrated a key from 1.1 to 2.0 but the documentation under Cryptography Application Block > Introduction to the Cryptography Application Block has a specific step-by-step process for migrating keys. Here is a copy-paste, but you can find it in the documentation:

To migrate existing keys

 - Open the application configuration file with the June 2005 release of the configuration console. 
 - In the right pane, click the ellipsis button (…) in the Key property section. The Key Creation dialog box appears. Click Export Key. This will export the key to a text file. 
 - In the Export Destination text box, enter the destination of the text file or click Browse and select the destination. Click OK. 
 - Add a new cryptography provider of the same type as the one associated with the key you exported. For example, if you exported a key used by a RijndaelManaged symmetric provider, add a new RijndaelManaged symmetric provider. In this example, right-click Symmetric Provider, point to New, and then click Symmetric Algorithm Provider. In the Type Selector dialog box, click RijndaelManaged, and then click OK. 
 - When the configuration console displays the Key Creation dialog box, click Import Key. 
 - In the Import Key dialog box, click the Browse button and select the key file that you created in step 3. 
 - The configuration console displays a message to indicate that the key has been successfully imported. Click OK. 
 - The configuration console displays the key in the Key Creation dialog box. Select the key and copy it to the clipboard. 
 - Close the configuration console. 
 - Use the January 2006 release of the configuration console to configure the Cryptography Application Block and to add a provider. The configuration console will launch the Cryptographic Key Wizard. For more information about configuring the Cryptography Application block, see Entering Configuration Information. 
 - Click Create a new key, and then click Next. 
 - In the text box, paste the key that you copied to the clipboard and click Next. 
 - Click the ellipsis button (…) and browse to the location where you want to store the key, and then click Next. 
 - Select either User mode or Machine mode, and then click Finish.




David Hayden
Microsoft MVP C#