Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Secure/Encrypted File Transfer

Posted on 2006-11-16
Medium Priority
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 750 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 http://www.mccune.cc/PGP.htm, 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

719 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