Fabrizio Accatino
Fabrizio Accatino

Reputation: 2292

Rijndael / AES from C# to VB6

I need to encrypt a byte array in VB6 and decrypt it in C# (NET 2.0). And viceversa (C# to VB6).

In C# I used RijndaelManaged class. In VB6 I used free pieces of from Internet. The best seems to be http://www.frez.co.uk/freecode.htm#rijndael But the two implementations generate different outputs starting from the same input :(

Perhaps it's a problem with the IV vector in RijndaelManaged ... I don't understand...

Any solution / experience using Rijndael / AES between VB6 and NET ? Or TripleDes....

thank you

UPDATE: IMPORTANT: The machine where vb6 app runs, has not NET framework. So I cannot use Interop and/or a NET wrapper class exposed as COM. :(

Upvotes: 4

Views: 5916

Answers (5)

Neo Cambell
Neo Cambell

Reputation: 127

If you can do a simple C to C# conversion here is a nice solution. It works great with VB6/php and C. Have a look at Encryption for C++, Visual Basic, php using PC1.

Upvotes: 0

Alex Bagnolini
Alex Bagnolini

Reputation: 22422

VbCorLib now supports cryptography, included Rijndael.

It's free and .NET-like. Link: http://vbcorlib.blogspot.com/

Upvotes: 0

Cheeso
Cheeso

Reputation: 192627

I just grabbed SlowAES, a Javascript implementation of AES, and embedded it into a Windows Script Component, which makes it accessible via COM. I was then able to call into the component from COM clients. I didn't try VB6 because i don't have Visual Studio 6. But for the COM clients I tried, I found the encryption to be completely compatible with .NET and the RijndaelManaged() class, when I use the same key, IV, mode, and keysize.

SlowAES is sort of limited; i didn't see an ECB mode for example. But the stuff I tested is compatible with .NET.

The source for the WSC file is available. That source also includes a RFC2898-compliant PBKDF2 usable from VB6. So you can set the key from a password. It is compatible with the Rfc2898DeriveBytes class in .NET.

See also, a related question.

Upvotes: 1

Migol
Migol

Reputation: 8447

Maybe I'll give you some informations regarding IV.

Initialization Vector is a clear-text sent data that should be generated randomly for each encryption to make stereotype headers attack harder or imposible to perform. Of course both encrypter and decrypter MUST have same value set.

Also there are some modes in which encryption and decryption may run. Have a look at this page: Wikipedia: Block cipher modes of operation. You should also ensure that this mode is same for both of them.

Upvotes: 0

Neil Barnwell
Neil Barnwell

Reputation: 42165

You could use interop from .NET to call the C# implementation from VB6. That way both sides would be using the same library.

Here's some additional info: http://msdn.microsoft.com/en-us/library/hfzzah2c(vs.71).aspx

Upvotes: 8

Related Questions