Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. :(

like image 294
Fabrizio Accatino Avatar asked Jan 23 '23 17:01

Fabrizio Accatino


2 Answers

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

like image 158
Neil Barnwell Avatar answered Jan 26 '23 05:01

Neil Barnwell


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.

like image 25
Cheeso Avatar answered Jan 26 '23 06:01

Cheeso