Encryption

Im a total newbie to Encryption im looking for the most simple way to encrypt and decrypt values with a cipher string no less than 128 i would like to use blowfish if possible. Im looking for very efficient module driven code because of the frequency that this will be used. The data will be stored in a databse.

Thank you in advance.
Greg
gharmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbrckoviCommented:
If you need realy simple algorythm then try to use this:

Create new project, add two listboxes, and two textboxes.
Paste this code.

To use this, enter your password in textbox1 and doubleclick on line in listbox1. After that, an encrypted text will appear in listbox2.
Double click on listbox2 item to get the decrypted text again in textbox2.

NOTE that this is maybe the most simple way to use password for encryption. It is very easy to break it, but it can be used for some simple things. (Like preventing your brother from reading your text files :) )

--------------------------------------------------------
Private Sub Form_Load()
    For X = 1 To 20
        List1.AddItem X & " Some text"
    Next X
End Sub

Private Sub List1_DblClick()
    Dim NewString As String
    NewString = Encrypt(List1.List(List1.ListIndex), Text1.Text)
    List2.AddItem NewString
End Sub

Function Encrypt(strText As String, strPassword As String)
    Dim PassLen As Integer
    Dim TextLen As Integer
    Dim TextChar As String
    Dim PassCharNum As Integer
    Dim PassChar As String
    Dim NewCharCode As Integer
    Dim newText As String
   
    PassLen = Len(strPassword)
    TextLen = Len(strText)
    PassCharNum = 1
   
    For X = 1 To TextLen
        TextChar = Mid(strText, X, 1)
        PassChar = Mid(strPassword, PassCharNum, 1)
        NewCharCode = Asc(TextChar) + Asc(PassChar)
        If NewCharCode > 255 Then NewCharCode = NewCharCode - 255
        newText = newText & Chr(NewCharCode)
        PassCharNum = PassCharNum + 1
        If PassCharNum > PassLen Then PassCharNum = 1
    Next X
   
    Encrypt = newText
End Function

Private Sub List2_DblClick()
    Dim NewString As String
    NewString = Decrypt(List2.List(List2.ListIndex), Text1.Text)
    Text2.Text = NewString
End Sub

Function Decrypt(strText As String, strPassword As String)
    On Error Resume Next
   
    Dim PassLen As Integer
    Dim TextLen As Integer
    Dim TextChar As String
    Dim PassCharNum As Integer
    Dim PassChar As String
    Dim NewCharCode As Integer
    Dim newText As String
   
    PassLen = Len(strPassword)
    TextLen = Len(strText)
    PassCharNum = 1
   
    For X = 1 To TextLen
        TextChar = Mid(strText, X, 1)
        PassChar = Mid(strPassword, PassCharNum, 1)
        NewCharCode = Asc(TextChar) - Asc(PassChar)
        If NewCharCode < 0 Then NewCharCode = 255 - NewCharCode
        newText = newText & Chr(NewCharCode)
        PassCharNum = PassCharNum + 1
        If PassCharNum > PassLen Then PassCharNum = 1
    Next X
   
    Decrypt = newText

End Function


0
dbrckoviCommented:
If you need more advenced methods try this as your starting point:

http://www.example-code.com/vb/aes.asp

0
dbrckoviCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

gharmanAuthor Commented:
I was just gonna post a comment asking how i got that. Thanks a lot. Im going to see if this works now.

Thanks

Greg
0
gharmanAuthor Commented:
IF this Chilkasoft something that has to be distrabuted with the application and how does the licensing work for it?

Greg
0
dbrckoviCommented:
This version is a 30 days trial. After that you have to buy it.

You should distribute and register ChilkatCrypt.dll with your app, but any install wizard should be able to do this for you.
Before doing that read a license.txt and other txt files for more information.

Basicaly it says that you can use this software, and distribute it with your app only if you have bought it and if your app is not based on this component.
0
vinnyd79Commented:
There is a good encryption library here that makes it easy to implement many popular Algorithms:

http://www.freevbcode.com/ShowCode.Asp?ID=3779

0
gharmanAuthor Commented:
The Chilkasoft seems to work great only access does not store the string properly it cuts off two non printing characthers at the end of each string. Anyone have any ideas on this. If there is a better database format to use im all ears now would be the time to change it if i am going to. I am just familar with the MS Jet 4.0 and its easy. Thanks in advance.

Greg
0
dbrckoviCommented:
I never used databases so I can't help you much in this field, but i'll try some blind shots.

Try storing ascii values of two last characters, and then reattach them when you need them, or try storing the whole string as an array of ascii values. I don't know if there is a function that already does this but try this:

This will store a string to a ascii array
---------------------------------------
    Dim asciiArray() As Integer
    Dim Length As Integer
   
    Length = Len(strText)
       
    ReDim asciiArray(Length - 1) As Integer
       
    For x = 1 To Length
        asciiArray(x - 1) = Asc(Mid(strText, x, 1))
    Next x

    For x = 0 To UBound(asciiArray)
        Print asciiArray(x)
    Next x
------------------------------------------------------------
0
gharmanAuthor Commented:
I have tried inputting the data manually into the database but it cuts off the last two characters.  Can you please show me how to trim a string. I want to trim the last two characters from the end of the string. This should solve my problem.

Greg
0
dbrckoviCommented:
NewString = Right(strText, 2)                            -> to get the last two characters
NewString = Left(strText, Len(strText) - 2)         -> to get evrything except the last two characters
0
dbrckoviCommented:
Thanx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.