Secure/Encrypted File Transfer

Posted on 2006-11-16
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

Question by:ShelfieldCollege
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 81

Accepted Solution

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)))

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)))

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

   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
         ByteHold = NibbleHold - 65 + 10
      End If
      NibbleHold = Asc(Mid$(HexSource, Position - 1, 1))
      If NibbleHold < 65 Then
         ByteHold = ByteHold + (NibbleHold - 48) * 16
         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
            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
      HexString = Hex$(EncodedByte)
      If Len(HexString) = 1 Then
         HexString = "0" & HexString
      End If
      EncodedString = HexString & EncodedString
   Translate = EncodedString

End Function


Expert Comment

ID: 17963304

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


Expert Comment

ID: 17963310

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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