Aug 1, 2016 06:03 PM
(This post was last modified: Aug 1, 2016 06:06 PM by x factor fan.)
hi friends..
today i was woking on a app that would encrypt a file to keep it safe from other ppl (i would pick a file to encrypt then i would need to enter passwords to unlock file).. the code works very good but the problem is when i encrypt a file over 255 bytes i get eception :( that say Key not valid for use in specified state ).. what can be problem? the key is fine.. any help would be great. thanks friends))..
my code..
i am russian by the way sorry for my english ((
today i was woking on a app that would encrypt a file to keep it safe from other ppl (i would pick a file to encrypt then i would need to enter passwords to unlock file).. the code works very good but the problem is when i encrypt a file over 255 bytes i get eception :( that say Key not valid for use in specified state ).. what can be problem? the key is fine.. any help would be great. thanks friends))..
my code..
Code
static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Import the RSA Key information. This only needs
//toinclude the public key information.
RSA.ImportParameters(RSAKeyInfo);
//Encrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
return encryptedData;
}
//Catch and display a CryptographicException
//to the console.
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(false), false);i am russian by the way sorry for my english ((


