Saher Naqi

Saher Naqi

  • NA
  • 1
  • 0

Encrypt bitmap image for C# Windows Application

Mar 19 2009 1:21 PM

I'm encrypting bitmap image(accessed from ms-access database) using RSACryptoServiceProvider.

private void button1_Click(object sender, System.EventArgs e)

{

string connString = "provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=D:\\practiceproject\practice.mdb";

OleDbConnection connection = new OleDbConnection(connString);

string commandString = "Select Image from readImage where ID=1";

OleDbCommand cmd = new OleDbCommand(commandString,connection);

byte[] toEncrypt = new byte[120154];

connection.Open();

toEncrypt = (Byte[]) cmd.ExecuteScalar();

connection.Close();

RSAParameters rsaPubParams;

RSAParameters rsaPrivateParams;

RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

//Generate public and private key data.

rsaPrivateParams = rsaCSP.ExportParameters(true);

rsaPubParams = rsaCSP.ExportParameters(false);

rsaCSP.ImportParameters(rsaPubParams);

byte[] encrypted = rsaCSP.Encrypt(toEncrypt, false);

}

But i get "Bad Length" error at "byte[] encrypted = rsaCSP.Encrypt(toEncrypt,false);"

Please help me to resolve this problem...I m in great trouble...