Link to home
Start Free TrialLog in
Avatar of whsean
whsean

asked on

Secure Encryption

Hi Experts,

Where can i find a very secure or well known standard (third party software or ...) encryption  software that can works with VB to save the data in encrypted format in SQL database?

This software must allow the user to select their encrypt or decrypt key

Thanks.
Sean
Avatar of bukko
bukko


Blowfish is always a good bet.
There are several 3rd part components on the net to do this.

bukko
ASKER CERTIFIED SOLUTION
Avatar of bukko
bukko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of whsean

ASKER


Which one is the correct bet? Does it allow the user the key-in the key to encrypt and decrypt?
Well, some development is obviously required.
...or are you looking for a ready made secure form of Enterprise Manager or similar browser?

bukko
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of whsean

ASKER

Hi  TMacT,

I have tried your solution, but the descrypt part seems not working well. It doesn't descrypt full original length of test.

Sean
Hi Sean,

I just tested it and found, as you, that characters were missing when I decrypted. I poked around a bit, and found if you show the encrypted string in a textbox, and then decrypt with the value of the textbox, characters are lost. So ... don't do that. :)

If you Encrypt to a variable, display or store the encrypted string, then use that same string to decrypt, the function works fine. It would seem that displaying the encrypted text strips out the non-displayable characters.

Let me know if you still have any problems.

... TMacT
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

There is only a problem if you "display" the encrypted result, then use the "displayed" text to decrypt. Other that for testing, there is no reason to do this. If you Encrypt, store the result, read in the result, and decrypt, without jamming the encrypted string into a text box, there is not a problem.

I did not do a hex dump, but I do not think that the problem characters were chr(0). There are many non-display characters that will be stripped from a text box.

... TMacT
In my experience vb text boxes have a go at rendering anything, except \00s.

And, the way the end of the string is going missing...
Avatar of whsean

ASKER

Hi TMacT,

I have tried the solution that you suggested where i stored the encrypted data to a string variable but the outcome still the same.
----------------------------------------------------------------------------------------
Dim tmpString As String

Private XCrypt As New ClsCrypt

Private Sub Command1_Click()
    tmpString = XCrypt.EncryptString(Text1.Text, Text3.Text)
    Text2.Text = tmpString
End Sub

Private Sub Command2_Click()
    Text2.Text = XCrypt.DecryptString(tmpString, Text3.Text)
End Sub
-----------------------------------------------------------------------------------------
Hi Whsean,

Sorry, been on Vacn.

I just tried your example, and it worked fine for several different combinations of source data and passphrases, short and long. Your function names are different from the ones that I have, so here is the VB class as I converted it.

=============================================
clsRC4Encrypt
=============================================
Option Explicit

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
':::  This script is Copyright © 1999 by Mike Shaffer            :::
':::  ALL RIGHTS RESERVED WORLDWIDE                              :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Dim sbox(255) As Integer
Dim key(255) As Integer

Public Function Decrypt(sSource As String, sPassphrase As String) As String
    Decrypt = EnDeCrypt(sSource, sPassphrase)
End Function

Public Function Encrypt(sSource As String, sPassphrase As String) As String
    Encrypt = EnDeCrypt(sSource, sPassphrase)
End Function


Private Sub RC4Initialize(strPwd As String)
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ':::  This routine called by EnDeCrypt function. Initializes the :::
   ':::  sbox and the key array)                                    :::
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

      Dim tempSwap As Integer
      Dim a As Integer
      Dim b As Integer
      Dim intLength As Integer
     

      intLength = Len(strPwd)
     
      For a = 0 To 255
         key(a) = Asc(Mid(strPwd, (a Mod intLength) + 1, 1))
         sbox(a) = a
      Next

      b = 0
      For a = 0 To 255
         b = (b + sbox(a) + key(a)) Mod 256
         tempSwap = sbox(a)
         sbox(a) = sbox(b)
         sbox(b) = tempSwap
      Next
   
End Sub
   
Private Function EnDeCrypt(plaintxt As String, psw As String) As String
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ':::  This routine does all the work. Call it both to ENcrypt    :::
   ':::  and to DEcrypt your data.                                  :::
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

      Dim temp As Integer
      Dim a As Integer
      Dim i As Integer
      Dim j As Integer
      Dim k As Integer
      Dim cipherby As Integer
      Dim cipher As String

      i = 0
      j = 0

      RC4Initialize psw

      For a = 1 To Len(plaintxt)
         i = (i + 1) Mod 256
         j = (j + sbox(i)) Mod 256
         temp = sbox(i)
         sbox(i) = sbox(j)
         sbox(j) = temp
   
         k = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher = cipher & Chr(cipherby)
      Next

      EnDeCrypt = cipher

End Function
=============================================
And the form code, so you can copy/paste to your form.
-------------------------------------------------------------------------------
Dim tmpString As String

Private XCrypt As New cRC4Encrypt

Private Sub Command1_Click()
    tmpString = XCrypt.Encrypt(Text1.Text, Text3.Text)
    Text2.Text = tmpString
End Sub

Private Sub Command2_Click()
    Text2.Text = XCrypt.Decrypt(tmpString, Text3.Text)
End Sub

Private Sub Form_Load()
    Text1 = "This is a test of the rc4 function."
    Text3 = "This is the passphrase."
   
   
End Sub
-------------------------------------------------------------------------------
Avatar of whsean

ASKER

Hi TMacT,

The Decrypt part is not working. Previously it descrypt partially but now it's a empty.

---------------Form Part------------
Dim tmpString As String

Dim XCrypt As New cRC4Encrypt

Private Sub Command1_Click()
    tmpString = XCrypt.Encrypt(Text1.Text, Text3.Text)
    Text2.Text = tmpString
End Sub

Private Sub Command2_Click()
    Text2.Text = XCrypt.Decrypt(tmpString, Text3.Text)
    Me.Refresh
End Sub

Private Sub Form_Load()
    Text1 = "This is a test of the rc4 function."
    Text3 = "This is the passphrase."
   
   
End Sub
--------------------------------------------------------

------------------cRC4Encrypt Module-------------------
Option Explicit

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
':::  This script is Copyright ? 1999 by Mike Shaffer            :::
':::  ALL RIGHTS RESERVED WORLDWIDE                              :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Dim sbox(255) As Integer
Dim key(255) As Integer

Public Function Decrypt(sSource As String, sPassphrase As String) As String
    Decrypt = EnDeCrypt(sSource, sPassphrase)
End Function

Public Function Encrypt(sSource As String, sPassphrase As String) As String
    Encrypt = EnDeCrypt(sSource, sPassphrase)
End Function


Private Sub RC4Initialize(strPwd As String)
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ':::  This routine called by EnDeCrypt function. Initializes the :::
   ':::  sbox and the key array)                                    :::
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

      Dim tempSwap As Integer
      Dim a As Integer
      Dim b As Integer
      Dim intLength As Integer
     

      intLength = Len(strPwd)
     
      For a = 0 To 255
         key(a) = Asc(Mid(strPwd, (a Mod intLength) + 1, 1))
         sbox(a) = a
      Next

      b = 0
      For a = 0 To 255
         b = (b + sbox(a) + key(a)) Mod 256
         tempSwap = sbox(a)
         sbox(a) = sbox(b)
         sbox(b) = tempSwap
      Next
   
End Sub
   
Private Function EnDeCrypt(plaintxt As String, psw As String) As String
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ':::  This routine does all the work. Call it both to ENcrypt    :::
   ':::  and to DEcrypt your data.                                  :::
   ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

      Dim temp As Integer
      Dim a As Integer
      Dim i As Integer
      Dim j As Integer
      Dim k As Integer
      Dim cipherby As Integer
      Dim cipher As String

      i = 0
      j = 0

      RC4Initialize psw

      For a = 1 To Len(plaintxt)
         i = (i + 1) Mod 256
         j = (j + sbox(i)) Mod 256
         temp = sbox(i)
         sbox(i) = sbox(j)
         sbox(j) = temp
   
         k = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher = cipher & Chr(cipherby)
      Next

      EnDeCrypt = cipher

End Function

----------------------------------------------
Hi Sean,

Other than provide you with a COPY / PASTE of the entire working project (above) I am not sure what to do. Can you try creating a new project with a form and just this class. I tested it on my workstation and laptop and it worked perfectly. There must be something unique to your development environment.

Text1 = text to encrypt
TEXT3 = passphrase

Text2 = displayed text - encrypted / decrypted.


... TMacT
Avatar of whsean

ASKER


Hi TMacT,

Would it be possible for you to provide an email address so that i could send the project over?

Thanks for the help as i really need it works.

Sean