Encrypt in VB6, decrypt in VB.NET? (and vice versa)
Encrypt in VB6, decrypt in VB.NET? (and vice versa)
I use DES Encrypt and Decrypt routines in VB.Net2003, using System.Security.Cryptography - something like:
| | Public Shared Function DESEncrypt(ByVal strKey As String, ByVal strData As String) As String Dim strValue As String = "" If strKey <> "" Then ' convert key to 16 characters for simplicity Select Case Len(strKey) Case Is < 16 strKey = strKey & Left("XXXXXXXXXXXXXXXX", 16 - Len(strKey)) Case Is > 16 strKey = Left(strKey, 16) End Select ' create encryption keys Dim byteKey() As Byte = Encoding.UTF8.GetBytes(Left(strKey, 8)) Dim byteVector() As Byte = Encoding.UTF8.GetBytes(Right(strKey, 8)) ' convert data to byte array Dim byteData() As Byte = Encoding.UTF8.GetBytes(strData) ' encrypt Dim objDES As New DESCryptoServiceProvider Dim objMemoryStream As New MemoryStream Dim objCryptoStream As New CryptoStream(objMemoryStream, objDES.CreateEncryptor(byteKey, byteVector), CryptoStreamMode.Write) objCryptoStream.Write(byteData, 0, byteData.Length) objCryptoStream.FlushFinalBlock() ' convert to string and Base64 encode strValue = Convert.ToBase64String(objMemoryStream.ToArray()) Else strValue = strData End If Return strValue End Function |
I'd like to be able use the same routines from VB6 code, so that I can encrypt/decrypt strings in legacy apps that share data with my VB.Net app.
Is this possible using the same routines or are there compatible classes I can reference in VB6 somewhere
Encrypt in VB6, decrypt in VB.NET? (and vice versa)
THHNO
CHTHONIC
Thanks Kelly.
I will check it out.
Duane
GianniAb
chaser7016
If anyone knows how to get shared functions to be visible when working with COM-interop from .NET, I would love to know!
kenc2005
If you don't mind going the 3rd party route, you could try my VB6 dll, VBCorLib. It supports all of the encryption routines mentioned and is compatible with the .NET versions. It's on Source Forge if you wish to try it. http://sourceforge.net/projects/vbcorlib/
Kelly
RonDesta
I would then call the same DLL from both places, so that your code has a common point of call.
InvertedAerials
I am running into the same requirement.
I need to be able to use CryptoAPI in a VB6 application that produces the same encrypted output that a VB.NET application does using the TripleDESCryptoServiceProvider.
Seems like a lot of folks would like to be able to do this. Are there any good simple examples of this If you have any, please post or provide a link where they can be found.
I like the poster above would like to use the CryptoAPI on the VB6 side as opposed to interop with the .NET DLL I created if possible.
Thanks
Discoman
BTW - I wouldn't store anything too sensitive using DES as it is fairly easily cracked using today's computing power. Triple-DES (aka 3DES) is much more secure. Even better algorithms would be Rijndael (pronounced rain-doll), AES or Blowfish.
A good intro to .NET cryptography is:
http://msdn.microsoft.com/msdnmag/issues/02/06/Crypto/default.aspx
You can find a .NET implementation of AES in this article:
http://msdn.microsoft.com/msdnmag/issues/03/11/AES/
You can find info on Blowfish here:
http://www.schneier.com/blowfish-products.html
Chandra B