3DES between .NET and VB

  • Thread starter Thread starter Joshua Ellul
  • Start date Start date
J

Joshua Ellul

Hi,

I have recently implemented the 3DES algorithm using .NET. However, all
implementations I have found in VB 6 do not work correctly with this
version. I imagine it is due to different string bases or some
architectural difference. Could someone point me to some material that
could help me implement the 3DES for VB that would comply with the .NET
version.

Best Regards,

Joshua Ellul
 
Joshua Ellul said:
Hi,

I have recently implemented the 3DES algorithm using .NET. However, all
implementations I have found in VB 6 do not work correctly with this
version. I imagine it is due to different string bases or some
architectural difference. Could someone point me to some material that
could help me implement the 3DES for VB that would comply with the .NET
version.

Best Regards,

Joshua Ellul

I think your best bet is to use the facilities already provided in the .NET
framework class libraries. The TripleDESCryptoServiceProvider class is the
managed implementation (wrapper, I believe) for TripleDES. Also, there is a
TripleDES abstract class you can inherit from if you want a jump-start on
rolling your own implementation.
 
Hi Jeremy,

I am using this class however I want to implement the 3DES algorithm in
Visual Basic 6. I have seen some implementations but the encryptions did
not ecrypt to the same source... or rather decrypt at all. I think it could
be due to different string bases i.e. 64 and 32 or an implementation
difference in the .NET 3Des class.

Regards,

Joshua
 
The .NET TripleDESCryptoServiceProvider is just a wrapper for the win32
CryptoAPI version of TripleDES.
You can try using the CryptoAPI from VB6 as one solution (though I don't
really recommend that).

Another is to create a COM-visible class from .NET that exposes the
TripleDES functionality. Then use RegAsm to register the .NET assembly and
reference it from VB6 just like it was a COM component.

However, all this is just skirting the issue. The .NET TripleDES class
creates standard Triple DES cipher data. Any other DES implementation should
be able to work with it. I think your biggest problem is understanding all
the options - particularly the options for CipherMode and Padding.
Obviously, you MUST use the same key and IV from both sides, and I hope
you're doing that already. After that, you must be aware that .NET
automatically uses CBC (cipher block chaining) mode and PKCS#7 padding by
default.

Cipher mode on the .NET side tells the algorithm what feedback mode to use.
You can use ECB (no feedback), CBC, OFB, CFB, or CTS. The decryption
algorithm must be able to use the same mode.

Then, you have padding. If your input isn't evenly divisible by the block
size, then padding is applied to the end before it is encrypted. The .NET
class uses PKCS#7 padding by default, but you can choose to pad with Zeros
or use no padding at all. Again, the decryption algorithm must support the
same padding you used for encryption.

-Rob Teixeira
 
What about building a .NET assembly that uses .NET 3DES, building a COM
wrapper for that Assembly, and then calling that wrapper from your VB6
applications?
 
Back
Top