Solved

Encryption

Posted on 2003-11-26
13
374 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:gharman
  • 7
  • 4
13 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823713
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823724
If you need more advenced methods try this as your starting point:

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

0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 200 total points
ID: 9823742
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:gharman
ID: 9823757
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
 

Author Comment

by:gharman
ID: 9823772
IF this Chilkasoft something that has to be distrabuted with the application and how does the licensing work for it?

Greg
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823825
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
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9824894
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
 

Author Comment

by:gharman
ID: 9829784
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9830197
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
 

Author Comment

by:gharman
ID: 9830243
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9830276
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 10171906
Thanx
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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