A few helpful hints (based on 3.5 sp1):
This object is a wrapper for an unmanaged API so ensure you use .Clear() in a try... finally block or a Using block (VB.NET) to dispose of your object.
Creating a new instance of this class will ALWAYS create a new private key (keypair). You can then overwrite it if needed by importing your own key using ImportCSPBlob, ImportParameters or FromXMLString.
If you want to persist your private key in a container, then you must initialise your object using CSPParameters and specify the KeyContainerName. This will set the persist flag on the object on initialisation. If you do not specify any parameters when initialising the object then the key will not persist.
It is important to note that the same KeyContainerName can hold 2 keys - one for each cspParams.KeyNumber (Encryption and Signature). ImportCSPBlob may change the cspParams.KeyNumber. If the BLOB was generated by the strong name tool then you must set cspParams.KeyNumber = KeyNumber.Signature (default is Keynumber.Encryption) in order to read the correct key from the container later.
The default container location is in a user profile. You can set this to machine in the CSPParameters object. The user version does not work well with websites as user profiles are not loaded by default. You need to use the machine version or change some IIS settings (there's a post about this out there somewhere).
Use cspParams.Flags += CspProviderFlags.UseNonExportableKey to protect your key from export, if necessary.
Public keys CANNOT be stored in containers. This is not stated anywhere in the documentation. Use ToXMLString instead or figure something else out (strong name tool has a nice ability to write out a byte array in csv format - good for hardcording the public key into source code, although I imagine this is not recommended practice).
From what I can gather, RSACryptoServiceProvider is not really designed to be used with the strong name tool. The private key (keypair) can be imported as is using ImportCSPBlob (set KeyNumber.Signature as above). The public key needs to have the first 12 bytes (an extra header) stripped before doing this.
'Example: Load up public key from strong name tool csv file (hardcoded in app)
Dim key As Byte() = {0, 36, ...}
or
'Example: Load up public key from strong name tool public key file
Dim key As Byte() = File.ReadAllBytes(Me.txtPublicKeyPath.Text)
or
'Example: Load up public key from strongly named assembly
Dim key As Byte() = Assembly.GetExecutingAssembly.GetName().GetPublicKey()
' Strip first 12 bytes (from all the above as all came from strong name tool)
Dim tmpKey As Byte() = New Byte(key.Length - 13) {}
Array.Copy(key, 12, tmpKey, 0, tmpKey.Length)
'Create a new RSA signing key and import key.
Dim cspParams As CspParameters = New CspParameters()
'Use MachineKeyStore to get around some permissions problems with the user store with websites (or tweak iis setting to load user profile).
cspParams.Flags = CspProviderFlags.UseMachineKeyStore
'KeyNumber not really needed to look at public key, but is needed to persist private key from strong name tool.
cspParams.KeyNumber = KeyNumber.Signature
'Note: we don't want to persist this key, so we are not specifying KeyContainerName here.
'If you want to persist a key in a container, specify KeyContainerName.
Using rsaKey As New RSACryptoServiceProvider(cspParams)
rsaKey.ImportCspBlob(tmpKey)
' Verify the signature of the signed XML.
Dim result As Boolean = VerifyXml(xmlLicence, rsaKey)
If result = False Then
...
End If
End Using
CSPBLOB Encoding differences
http://www.vsj.co.uk/dotnet/display.asp?id=590
http://www.jensign.com/JavaScience/dotnet/JKeyNet/