Solved

Secure/Encrypted File Transfer

Posted on 2006-11-16
3
238 Views
Last Modified: 2010-04-30
Hi all,

I have a requirement in VB to send files from various machines to a central storage server.  One problem is that I have the need to ensure the data transmitted can't be read during it's travels, e.g. needs to be secure/encrypted as the information is personal details of people.

I'm open to any/all suggestions for ways of sending files secure between computers (essentially over a WAN), although I do request that people don't suggest the use of commercial controls/components or other third party controls etc.

Many Thanks

Matt
0
Comment
Question by:ShelfieldCollege
  • 2
3 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 250 total points
ID: 17961679
I use the following encoding/decoding function. It's fast but it is not NSA secure. I would not be able to decode it without the function below but I'm not a crytographer.

Option Explicit

Private Enum Direction
   Encoding = 1
   Decoding = 2
End Enum

Public Function Decode( _
      ByRef Source As String _
   ) As String

' Decode the source string encrypted with the Encode function. The source must be an even number
' of characters.

   Dim HexString As String
   
   If Len(Source) Mod 2 = 1 Then Exit Function
   HexString = Translate(Source, Decoding)
   Decode = HexToString(HexString)

End Function

Public Function Encode( _
      ByRef Source As String _
   ) As String

' Encode the source string. The result is an encrypted hex string.

   Dim HexString As String
   
   HexString = StringToHex(Source)
   Encode = Translate(HexString, Encoding)

End Function

Public Function HexToString( _
      ByRef Source As String _
   ) As String

' Converts a string of hex to a string. The hex string must be an even number of characters.
   
   Dim Index As Long
   
   If LCase(Left(Source, 2)) = "0x" Then Source = Right(Source, Len(Source) - 2)
   
   If Len(Source) Mod 2 = 1 Then Exit Function
   For Index = 1 To Len(Source) Step 2
      HexToString = HexToString & Chr(Val("&H" & Mid(Source, Index, 2)))
   Next

End Function

Public Function StringToHex( _
      ByRef Source As String _
   ) As String

' Converts the string to a hex.
   
   Dim Index As Long
   
   For Index = 1 To Len(Source)
      StringToHex = StringToHex & Hex(Asc(Mid(Source, Index, 1)))
   Next

End Function

Private Function Translate( _
      ByRef HexSource As String, _
      ByRef Direction As Direction _
   ) As String

' Encodes and decodes a display hex string. The function reverses the encoding each time
' it is called with the same string. To use this function with any data, convert that data
' to a display hex format first.
   
   Dim EncodedString As String
   Dim Position As Integer
   Dim NibbleHold As Integer
   Dim ByteHold As Integer
   Dim EncodedByte As Integer
   Dim BitIndex As Integer
   Dim BitHold As Integer
   Dim HexString As String
   
   ReDim ShiftArray(24) As Integer
   Dim ArrayIndex As Integer
   Const M0 = 5

   ' Initialize...

   For ArrayIndex = 0 To UBound(ShiftArray)
      ShiftArray(ArrayIndex) = 0
   Next

   ShiftArray(5) = 1
   ShiftArray(4) = 0
   ShiftArray(3) = 0
   ShiftArray(2) = 1
   ShiftArray(1) = 1
   
   ' Encode the string
   
   EncodedString = ""
   ArrayIndex = 0
   
   For Position = Len(HexSource) To 1 Step -2
      EncodedByte = 0
      NibbleHold = Asc(Mid$(HexSource, Position, 1))
      If NibbleHold < 65 Then
         ByteHold = NibbleHold - 48
      Else
         ByteHold = NibbleHold - 65 + 10
      End If
      NibbleHold = Asc(Mid$(HexSource, Position - 1, 1))
      If NibbleHold < 65 Then
         ByteHold = ByteHold + (NibbleHold - 48) * 16
      Else
         ByteHold = ByteHold + (NibbleHold - 65 + 10) * 16
      End If
      For BitIndex = 0 To 7
         BitHold = (ByteHold And 2 ^ BitIndex) / 2 ^ BitIndex
         If Direction = Encoding Then
            ShiftArray(ArrayIndex) = BitHold
            BitHold = (BitHold + ShiftArray((ArrayIndex + M0) Mod UBound(ShiftArray)) + ShiftArray((ArrayIndex + (UBound(ShiftArray) - 1)) Mod UBound(ShiftArray))) Mod 2
         Else
            BitHold = (BitHold + ShiftArray((ArrayIndex + M0) Mod UBound(ShiftArray)) + ShiftArray((ArrayIndex + (UBound(ShiftArray) - 1)) Mod UBound(ShiftArray))) Mod 2
            ShiftArray(ArrayIndex) = BitHold
         End If
         ArrayIndex = (ArrayIndex + UBound(ShiftArray) - 1) Mod UBound(ShiftArray)
         EncodedByte = EncodedByte + BitHold * 2 ^ BitIndex
      Next
      HexString = Hex$(EncodedByte)
      If Len(HexString) = 1 Then
         HexString = "0" & HexString
      End If
      EncodedString = HexString & EncodedString
   Next
   
   Translate = EncodedString

End Function

Kevin
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 17963304
Hello.

If you really want good security of your data, you could use PGP encryption.
See this link http://www.mccune.cc/PGP.htm, there are some COM interfaces to PGP, and it's freeware.

Regards,
Julian.
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 17963310
P.S.

This is the direct link to the DLL that supports PGP:

http://community.wow.net/grt/nsdpgp.html
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now