Hi All,
I have a program written in VB6 which utilize CryptoAPI to encrypt bitmap
file.
I'm writting a new program in C# 2005 to decrypt those encrypted bitmap file
by adding the CryptoAPI reference in my C# project. Everything seem fine, i
have no problem when execute the program.
But when I click the button to decrypt the bitmap file, there is an error
occurs "Could not decrypt data. A critical error occurred during the
decryption process". I can't figure out which part is wrong.
Below is the code for decryption:
string f = @"C:\Temp\blue hills.enc";
string myfile = @"C:\Temp\decrypt.jpg";
CryptKci.clsCryptoAPI crypto = new CryptKci.clsCryptoAPI();
byte[] pwbyte = ASCIIEncoding.ASCII.GetBytes(key);
Array myarr = (Array)pwbyte;
crypto.set_Password(ref myarr);
FileStream fs = new FileStream(f, FileMode.Open,
FileAccess.Read);
byte[] b = new byte[fs.Length];
fs.Read(b, 0, b.Length);
Array myarr1 = (Array)b;
crypto.set_InputData(ref myarr1);
string mytext = "";
if (crypto.Decrypt(2, 3))
{
Array myarr2 = crypto.OutputData;
mytext = crypto.ByteArrayToString(ref myarr2);
}
byte[] b1 = ASCIIEncoding.ASCII.GetBytes(mytext);
FileStream fs1 = new FileStream(myfile, FileMode.Create,
FileAccess.Write);
fs1.Write(b1, 0, b1.Length);
fs1.Close();
// //NU_Decrypt(b, b.Length, key, key.Length);
fs.Close();
NOTE: I'm using the same DLL that I use in VB6 to import into my C# project.
Also the password use to encrypt is password.
Any advice is much appreciated. Thanks in advance.
--
Regards,
Venedict