I need to encrypt a byte array in VB6 and decrypt it in C# (NET 2.0). And viceversa (C# to VB6).
我需要在VB6中加密一个字节数组并在C#(NET 2.0)中解密它。反之亦然(C#到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 :(
在C#中我使用了RijndaelManaged类。在VB6中,我使用了来自Internet的免费部分。最好的似乎是http://www.frez.co.uk/freecode.htm#rijndael但这两个实现从相同的输入开始生成不同的输出:(
Perhaps it's a problem with the IV vector in RijndaelManaged ... I don't understand...
也许这是RijndaelManaged中IV矢量的问题......我不明白......
Any solution / experience using Rijndael / AES between VB6 and NET ? Or TripleDes....
在VB6和NET之间使用Rijndael / AES的任何解决方案/经验?或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. :(
更新:重要:运行vb6 app的机器,没有.NET框架。所以我不能使用Interop和/或作为COM公开的.NET包装类。 :(
6 个解决方案
#1
You could use interop from .NET to call the C# implementation from VB6. That way both sides would be using the same library.
您可以使用.NET中的interop从VB6调用C#实现。这样双方都会使用相同的库。
Here's some additional info: http://msdn.microsoft.com/en-us/library/hfzzah2c(vs.71).aspx
这里有一些额外的信息:http://msdn.microsoft.com/en-us/library/hfzzah2c(vs.71).aspx
#2
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,一个AES的Javascript实现,并将其嵌入到Windows脚本组件中,这使得它可以通过COM访问。然后我能够从COM客户端调用组件。我没有尝试VB6,因为我没有Visual Studio 6.但对于我尝试的COM客户端,我发现加密与.NET和RijndaelManaged()类完全兼容,当我使用相同的密钥时,IV ,模式和密钥。
SlowAES is sort of limited; i didn't see an ECB mode for example. But the stuff I tested is compatible with .NET.
SlowAES有点受限;例如,我没有看到ECB模式。但我测试的东西与.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.
可以使用WSC文件的源代码。该源还包括可从VB6使用的符合RFC2898的PBKDF2。所以你可以从密码设置密钥。它与.NET中的Rfc2898DeriveBytes类兼容。
See also, a related question.
另见相关问题。
#3
Maybe I'll give you some informations regarding IV.
也许我会给你一些关于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.
还有一些模式可以运行加密和解密。看看这个页面:*:分组密码操作模式。您还应该确保这两种模式都相同。
#5
VbCorLib now supports cryptography, included Rijndael.
VbCorLib现在支持加密,包括Rijndael。
It's free and .NET-like. Link: http://vbcorlib.blogspot.com/
它是免费的,像.NET一样。链接:http://vbcorlib.blogspot.com/
#6
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.
如果你可以做一个简单的C到C#转换,这是一个很好的解决方案。它适用于VB6 / php和C.使用PC1查看加密C ++,Visual Basic,php。
#1
You could use interop from .NET to call the C# implementation from VB6. That way both sides would be using the same library.
您可以使用.NET中的interop从VB6调用C#实现。这样双方都会使用相同的库。
Here's some additional info: http://msdn.microsoft.com/en-us/library/hfzzah2c(vs.71).aspx
这里有一些额外的信息:http://msdn.microsoft.com/en-us/library/hfzzah2c(vs.71).aspx
#2
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,一个AES的Javascript实现,并将其嵌入到Windows脚本组件中,这使得它可以通过COM访问。然后我能够从COM客户端调用组件。我没有尝试VB6,因为我没有Visual Studio 6.但对于我尝试的COM客户端,我发现加密与.NET和RijndaelManaged()类完全兼容,当我使用相同的密钥时,IV ,模式和密钥。
SlowAES is sort of limited; i didn't see an ECB mode for example. But the stuff I tested is compatible with .NET.
SlowAES有点受限;例如,我没有看到ECB模式。但我测试的东西与.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.
可以使用WSC文件的源代码。该源还包括可从VB6使用的符合RFC2898的PBKDF2。所以你可以从密码设置密钥。它与.NET中的Rfc2898DeriveBytes类兼容。
See also, a related question.
另见相关问题。
#3
Maybe I'll give you some informations regarding IV.
也许我会给你一些关于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.
还有一些模式可以运行加密和解密。看看这个页面:*:分组密码操作模式。您还应该确保这两种模式都相同。
#4
#5
VbCorLib now supports cryptography, included Rijndael.
VbCorLib现在支持加密,包括Rijndael。
It's free and .NET-like. Link: http://vbcorlib.blogspot.com/
它是免费的,像.NET一样。链接:http://vbcorlib.blogspot.com/
#6
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.
如果你可以做一个简单的C到C#转换,这是一个很好的解决方案。它适用于VB6 / php和C.使用PC1查看加密C ++,Visual Basic,php。