Home All Groups Group Topic Archive Search About

NTE_BAD_DATA error with RSACryptoServiceProvider

Author
21 Jul 2006 5:58 PM
venkateswarag
Hi,

I am writing a string encrypt/decrypt for Pocket PC device using
RSACryptoServiceProvider class(OpenNETCF.Security.Cryptography) and
able the encrypt the string but getting the error while decrypting

Code snippets as follows

string pwdStr = "" test ;
//Encrypt
public string EncryptStr(string pwdStr)
{

RSACryptoServiceProvider rsa = new
RSACryptoServiceProvider(OpenNETCF.Security.Cryptography.NativeMethods.KeySpec.KEYEXCHANGE,
true);
byte[] cryptdata = rsa.EncryptValue(Encoding.UTF8.GetBytes(pwdStr));
string EncCredentials = Convert.ToBase64String(cryptdata, 0,
cryptdata.Length);

return EncCredentials;
}

//Decrypt
public string DecryptStr(string pwdStr1)
{
RSACryptoServiceProvider rsa1 = new
RSACryptoServiceProvider(OpenNETCF.Security.Cryptography.NativeMethods.KeySpec.KEYEXCHANGE,
true);
byte[] decryptdata =
rsa1.DecryptValue(Encoding.UTF8.GetBytes(pwdStr1));

//Getting "bNb.Sec: NTE_BAD_DATA" error here
string DecCredentials = Convert.ToBase64String(decryptdata, 0,
decryptdata.Length);

return DecCredentials;
}

Thanks for any help

Rgds,
Varsha

Author
28 Jul 2006 9:01 AM
serge calderara
Most of the time this errors comes when Key or vector are not the same for
encryption and decryption

Show quoteHide quote
"venkateswa***@gmail.com" wrote:

> Hi,
>
> I am writing a string encrypt/decrypt for Pocket PC device using
> RSACryptoServiceProvider class(OpenNETCF.Security.Cryptography) and
> able the encrypt the string but getting the error while decrypting
>
> Code snippets as follows
>
> string pwdStr = "" test ;
> //Encrypt
> public string EncryptStr(string pwdStr)
> {
>
> RSACryptoServiceProvider rsa = new
> RSACryptoServiceProvider(OpenNETCF.Security.Cryptography.NativeMethods.KeySpec.KEYEXCHANGE,
> true);
> byte[] cryptdata = rsa.EncryptValue(Encoding.UTF8.GetBytes(pwdStr));
> string EncCredentials = Convert.ToBase64String(cryptdata, 0,
> cryptdata.Length);
>
> return EncCredentials;
> }
>
> //Decrypt
> public string DecryptStr(string pwdStr1)
> {
> RSACryptoServiceProvider rsa1 = new
> RSACryptoServiceProvider(OpenNETCF.Security.Cryptography.NativeMethods.KeySpec.KEYEXCHANGE,
> true);
> byte[] decryptdata =
> rsa1.DecryptValue(Encoding.UTF8.GetBytes(pwdStr1));
>
> //Getting "bNb.Sec: NTE_BAD_DATA" error here
> string DecCredentials = Convert.ToBase64String(decryptdata, 0,
> decryptdata.Length);
>
> return DecCredentials;
> }
>
> Thanks for any help
>
> Rgds,
> Varsha
>
>