PC Review


Reply
Thread Tools Rate Thread

CryptoAPI in C# and VB6

 
 
=?Utf-8?B?VmVuZWRpY3Q=?=
Guest
Posts: n/a
 
      26th Dec 2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CryptoAPI DRIESSEN Michel Windows XP Work Remotely 5 15th Dec 2004 02:17 AM
CryptoAPI DRIESSEN Michel Windows XP Basics 2 2nd Dec 2004 03:23 PM
PcAnyWhere Cryptoapi is not available Reza Windows XP General 0 8th Jul 2004 06:20 AM
CryptoAPI question... =?Utf-8?B?RGFuaWwgU2hlYm91bmlu?= Microsoft Dot NET Framework 0 9th Feb 2004 05:11 PM
About CryptoApi and multithreading Aleksey Rechinsky Microsoft Windows 2000 Developer 0 12th Aug 2003 12:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.