Hi,
I'm getting the dreaded "Key not valid for use in specified state." with the RSACryptoServiceProvider (vb.net 2008) when trying to encrypt a byte block of under 245 bytes using a public key loaded from an xml string.
I have searched everywhere for this, but the only answers I can find relate to the length of the data being encrypted which isn't the problem here because the length of the data I'm trying to encrypt is only 193 bytes.
I have checked the public key being used with the original key and they are exactly the same.
I would post my code but its dotted around quite a few classes. Its something like the following:
Then Later on, in the sending class
Can anyone help?
Thanks loads in advance,
Chris
I'm getting the dreaded "Key not valid for use in specified state." with the RSACryptoServiceProvider (vb.net 2008) when trying to encrypt a byte block of under 245 bytes using a public key loaded from an xml string.
I have searched everywhere for this, but the only answers I can find relate to the length of the data being encrypted which isn't the problem here because the length of the data I'm trying to encrypt is only 193 bytes.
I have checked the public key being used with the original key and they are exactly the same.
I would post my code but its dotted around quite a few classes. Its something like the following:
Code:
'Generate key
Dim xmlpublickey As String
Dim rsa As New RSACryptoServiceProvider
xmlpublickey = rsa.ToXmlString(False)
Then Later on, in the sending class
Code:
Dim xmlpublickey As String = getKey() 'this key does match exactly (also in length)
Dim rsa As New RSACryptoServiceProvider
rsa.FromXmlString(xmlpublickey)
Return rsa.Encrypt(data, False) 'Error here
Can anyone help?
Thanks loads in advance,
Chris