473,792 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\bl ue hills.enc";
string myfile = @"C:\Temp\decry pt.jpg";
CryptKci.clsCry ptoAPI crypto = new CryptKci.clsCry ptoAPI();
byte[] pwbyte = ASCIIEncoding.A SCII.GetBytes(k ey);
Array myarr = (Array)pwbyte;
crypto.set_Pass word(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_Inpu tData(ref myarr1);
string mytext = "";

if (crypto.Decrypt (2, 3))
{
Array myarr2 = crypto.OutputDa ta;
mytext = crypto.ByteArra yToString(ref myarr2);
}
byte[] b1 = ASCIIEncoding.A SCII.GetBytes(m ytext);
FileStream fs1 = new FileStream(myfi le, FileMode.Create ,
FileAccess.Writ e);
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 3248

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

Similar topics

2
4663
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: Provider DLL failed to initialize correctly. On Win2000/2003 XP we not get this error any one come across this before
0
1904
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 to type the password for my certificate every time my program signs a mail :o( My program is a windows service running on a server so typing passwords is bad.
3
7786
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 the SecretKey Java class. However when I use this key in .NET i cannot decrypt the cipher text. I am pretty sure that all my settings are correct, as far as setting the ECB mode, PKCS5 padding and converting the cipher text to byte
4
6462
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 cryptographic service provider (CSP) for this implementation could not be acquired. I am using DPAPI(Machine Store) to encrypt a connection string. The decryption code is as follows: private string GetConnectionString() { DataProtector dp...
1
1902
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. I don't setup RSACryptoServiceProvider using CspParameters and I didn't give the RSA initiator any paramters when I setup the class yet, each implementation of the RSA class, as a web service, is creating a cryptoAPI storage bin for the RSA...
0
343
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 party use CryptoAPI C++ function:
0
1083
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 CRYPT_NEWKEYSET as the last parameter, then the rest of the crypt functions seem to work. But I came across an instance when I stopped debugging the program, before I had called CryptReleaseContext, and when I ran the program again, I got FALSE returned, and...
0
1355
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 site within the server, the exception goes away. My ASP page only displays the logon user (only 2 lines of code). I don't understand this behavior at all.
1
1861
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 are giving different output. how can i resolve this. In. .net component i am using "PasswordDeriveBytes" class to generated the key. algorithm used in "RC2" and Hash used in MD5. Pleae help
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.