PDA

Click to See Complete Forum and Search --> : Crypted Connection , needed ?


dBlues
Aug 10th, 2007, 08:23 PM
my project is file transfer ,

what I need is a way to encrypt and decrypt the data with a key , i did try to use modRC4.bas but the the sent file is damaged !

can you help me please ?

DigiRev
Aug 11th, 2007, 04:37 PM
Kinda hard to help you without seeing:

1. Your code
2. The encryption code
3. What parts of the file you are encrypting and if you're decrypting those same parts
4. How you're transferring your file
etc...

Lozzenger
Aug 17th, 2007, 11:57 AM
Here is a basic encryption/decryption algorithm that i created that works with string variables.
Read a chunk of the file at a time and pass it through EncryptString before sending. Then on receiving end use DecryptString on received data before writing to file.

Option Explicit

Private Const EncKey As String = "GST5DKHGV7VH4RK&^kmG8&%87TYKhg"

Public Function EncryptString(sData As String) As String
'Encryption
Dim keypos As Integer, i As Integer, buf As Integer
keypos = 1
If Len(sData) > 0 Then
'loop for every character
For i = 1 To Len(sData)
'perform ascii addition
buf = Asc(Mid(sData, i, 1)) + Asc(Mid(EncKey, keypos, 1))
'correct buffer if it goes over ascii limit
If buf > 255 Then
buf = buf - 256
End If
'Add to return parameter
EncryptString = EncryptString & Chr$(buf)
'advance keypos
If keypos = Len(EncKey) Then
keypos = 1
Else
keypos = keypos + 1
End If
Next i
End If
End Function

Public Function DecryptString(sData As String) As String
'Decryption
Dim keypos As Integer, i As Integer, buf As Integer
keypos = 1
If Len(sData) > 0 Then
'loop for every character
For i = 1 To Len(sData)
'perform ascii subtraction
buf = Asc(Mid(sData, i, 1)) - Asc(Mid(EncKey, keypos, 1))
'correct buffer if it goes over ascii limit
If buf < 0 Then
buf = 256 - Abs(buf)
End If
'Add to return parameter
DecryptString = DecryptString & Chr$(buf)
'advance keypos
If keypos = Len(EncKey) Then
keypos = 1
Else
keypos = keypos + 1
End If
Next i
End If
End Function

dilettante
Aug 17th, 2007, 02:57 PM
One should keep in mind that VB String variables should not be used for binary data. There are many places where the text of a String is converted from internal Unicode to ANSI/ASCII and back. Not all of these conversions are symmetric for all possible character values, some of which binary data may tend to run into more often than plain text.

Lozzenger
Aug 18th, 2007, 06:23 AM
It depends on what sort of file is being sent. If the file is plaintext without special characters then strings are ok, however if your sending files like videos or music then you'll need to use a byte array.
The algorithm can easily be altered to work with byte arrays instead of strings

dBlues
Aug 19th, 2007, 03:30 PM
I will try yours Lozzenger ...

dBlues
Aug 19th, 2007, 03:37 PM
thanx Lozzenger alot , it's working very well with all types of files :)

dBlues
Aug 19th, 2007, 04:08 PM
but it increases size of data alot :(

Lozzenger
Aug 19th, 2007, 04:34 PM
I don't see why it would increase the data size when it returns a string that's the same length as the one you passed in the function

Al42
Aug 21st, 2007, 11:15 AM
Also be aware that if you're transferring the files by FTP, you have to specify binary transfer. ASCII transfer can modify a file.

dBlues
Oct 29th, 2007, 06:54 PM
It depends on what sort of file is being sent. If the file is plaintext without special characters then strings are ok, however if your sending files like videos or music then you'll need to use a byte array.
The algorithm can easily be altered to work with byte arrays instead of strings


how can I modify it to work with byte arrays instead of strings?

dBlues
Nov 2nd, 2007, 05:19 AM
how can I modify it to work with byte arrays instead of strings?

thnx

Hack
Nov 7th, 2007, 09:10 AM
Is this still a question?

dBlues
Nov 9th, 2007, 05:20 AM
Is this still a question?

yeah, I still can't modify it to work with byte arrays instead of strings