C
casey chesnut
i've received a couple questions regarding RSA and this error.
for code like the following:
using OpenNETCF.Security.Cryptography;
RSACryptoServiceProvider rsa = new
RSACryptoServiceProvider(KeySpec.KEYEXCHANGE, true);
string txtPublicKey = rsa.ToXmlString(false);
string txtPrivateKey = rsa.ToXmlString(true);
string str = "this is some text to encrypt";
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
rsa1.FromXmlString(txtPublicKey);
byte[] encryptedStrAsBytes =
rsa1.EncryptValue(Encoding.Unicode.GetBytes(str));
string encryptedStrAsString =
Encoding.Unicode.GetString(encryptedStrAsBytes, 0,
encryptedStrAsBytes.Length);
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
rsa2.FromXmlString(txtPrivateKey);
byte [] decVal =
rsa2.DecryptValue(Encoding.Unicode.GetBytes(encryptedStrAsString));
string origVal = Encoding.Unicode.GetString(decVal, 0, decVal.Length);
this works for me on PPC 2003 emulator, and device, SP 2003 emu, and device.
chances are this is failing because you are on a PPC 2002 emulator,
because it does not have the high encryption pack installed.
the bNb.Sec.Context class has a property you can check:
bNb.Sec.Context.IsEnhanced
this will let you know if the Enhanced Crypto is installed on the device,
so that you can do pub/priv key encryption and signing.
Thanks,
casey
http://www.brains-N-brawn.com
for code like the following:
using OpenNETCF.Security.Cryptography;
RSACryptoServiceProvider rsa = new
RSACryptoServiceProvider(KeySpec.KEYEXCHANGE, true);
string txtPublicKey = rsa.ToXmlString(false);
string txtPrivateKey = rsa.ToXmlString(true);
string str = "this is some text to encrypt";
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
rsa1.FromXmlString(txtPublicKey);
byte[] encryptedStrAsBytes =
rsa1.EncryptValue(Encoding.Unicode.GetBytes(str));
string encryptedStrAsString =
Encoding.Unicode.GetString(encryptedStrAsBytes, 0,
encryptedStrAsBytes.Length);
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
rsa2.FromXmlString(txtPrivateKey);
byte [] decVal =
rsa2.DecryptValue(Encoding.Unicode.GetBytes(encryptedStrAsString));
string origVal = Encoding.Unicode.GetString(decVal, 0, decVal.Length);
this works for me on PPC 2003 emulator, and device, SP 2003 emu, and device.
chances are this is failing because you are on a PPC 2002 emulator,
because it does not have the high encryption pack installed.
the bNb.Sec.Context class has a property you can check:
bNb.Sec.Context.IsEnhanced
this will let you know if the Enhanced Crypto is installed on the device,
so that you can do pub/priv key encryption and signing.
Thanks,
casey
http://www.brains-N-brawn.com