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

x
?
Solved

Secure/Encrypted File Transfer

Posted on 2006-11-16
3
Medium Priority
?
246 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
[X]
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
3 Comments
 
LVL 81

Accepted Solution

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

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