NTE_BAD_KEY - RSA Cryptography

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: casey chesnut (casey_at_braSPAMins-N-braSPAMwn.com)
Date: 05/25/04


Date: Tue, 25 May 2004 10:04:46 -0500

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



Relevant Pages

  • RE: RSA Encryption: Saving keys as files, and size of encrypted da
    ... private static void GenerateKeys(string pubFile, ... The asymmetric encryption is not suitable for the encryption of large ... Could I ask for some help with RSACryptoServiceProvider class. ... Dim RSA As RSACryptoServiceProvider = New ...
    (microsoft.public.dotnet.security)
  • RSA Encryption: Saving keys as files, and size of encrypted data
    ... Could I ask for some help with RSACryptoServiceProvider class. ... files, and the other 2 apps encrypt and decrypt, using those xml strings. ... Dim RSA As RSACryptoServiceProvider = New ... Dim PubKey as string = RSA.ToXmlString ...
    (microsoft.public.dotnet.security)
  • NTE_BAD_DATA error with RSACryptoServiceProvider
    ... I am writing a string encrypt/decrypt for Pocket PC device using ... able the encrypt the string but getting the error while decrypting ... RSACryptoServiceProvider rsa = new ...
    (microsoft.public.dotnet.security)
  • Re: Byte array to string and back - newbie question
    ... // Create a symmetric algorithm. ... This is done to make encryption more ... // Encrypt a string into a string using a password ... // Decrypt a byte array into a byte array using a key and an IV ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Using Python To Create An Encrypted Container
    ... an encrypted archive utility designed for secure archiving ... A match string allows you to only extract files matching a given ... Encrypt the string s using passwd and encryption cipher enc ...
    (comp.lang.python)