473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

CryptoAPI in C# and VB6

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
Dec 26 '06 #1
0 3208

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy Atherton | last post by:
When using SQL 2000 personal desktop (i.e MSDE) on win 98 Machine with our VB6 application we sometimes get this error CryptoAPI function 'CryptAcquireContext' failed. Error 0x8009001d:...
0
by: Kim HM | last post by:
I Have a .NET program sending mails using CDOEX. These mail I need to sign. I god a tip that i shoud use CAPICOM. That worked fine sending a mail with signature. BUT the problem is that I have...
3
by: Michael Bebenita | last post by:
Hi, A Java application is encrypting a block of text using 3DES ECB mode and PKCS5 padding. I need to decrypt this text using C#. I've extracted the 192 bit key using the getEncoded() method of...
4
by: Dave Bailey | last post by:
I have an application installed on a web server. When forst intalled it worked fine. The administrator rebooted the server and then when accessing the app the folowing error appears: CryptoAPI...
1
by: Greg Merideth | last post by:
I've finally got my client/server secure soap process working and I've just noticed that under the servers \NetworkService\AppData\MS\Crypto\RSA folder there are some 100+ paired sets of RSA keys....
0
by: no game | last post by:
I have a problem with signature using RSACryptoServiceProvider I use signature=privKey.SignData(byteData, new MD5CryptoServiceProvide), and get a byte array of signature. The other...
0
by: Bonj | last post by:
Hi i have a question regarding the CryptoAPI. I can seemingly call CryptAcquireContext, and if I pass any random string as the key container name and NULL as the provider name, with...
0
by: Mike P | last post by:
This is a very weird problem, when I boot my IIS server I get a CryptoAPI cryptographic service provider (CSP) for this implementation could not be acquired exception. However, once I access my...
1
by: MichaelAni | last post by:
Hi, I have a requirement to develop an component in VC++ and .net for encryption/decryption. I am deriving a key from a password. But when i encrypt the data VC++(cryptoapi) component and .net...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.