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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

627 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