Hi,
I am using the OpenNETCF's cryptography namespace but got stuck, please help
me if you can spare some time.
How can I use the OpenNETCF.Security.Cryptography namespace? There is no
sample available for the classes in this namespace.
I am using the RSACryptoServiceProvider class to encrypt/decrypt my data I
get the keys using this code:
RSACryptoServiceProvider rsa = new
RSACryptoServiceProvider(KeySpec.KEYEXCHANGE, true);
txtPublicKey.Text = rsa.ToXmlString(false);
txtPrivateKey.Text = rsa.ToXmlString(true);
When it comes to encrypt, I write the following code:
string str = txtTextToEncrypt.Text;
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
// ---Load the public key---
rsa1.FromXmlString(txtPublicKey.Text);
byte[] encryptedStrAsBytes =
rsa1.EncryptValue(Encoding.Unicode.GetBytes(str));
string encryptedStrAsString = Encoding.Unicode.GetString(
encryptedStrAsBytes, 0, encryptedStrAsBytes.Length);
txtEncrypted.Text = encryptedStrAsString;
But there is always an exception raised when calling the encrypt saying
'NTE_BAD_KEY'
I am using the similar code at desktop using .Net's standard APIs without
any problem. Can someone identify the problem? or may point to some sample?
Waiting for the quick reply.
Regards,
Faraz Rasheed
(e-mail address removed)
Software Engineer
yEvolve Pvt. Ltd.
http://www.yevolve.com