Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Encryption

Encryption

Scheduled Pinned Locked Moved Visual Basic
csharpasp-netsharepointcomsysadmin
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpavas
    wrote on last edited by
    #1

    Hello, I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa. I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails. Please help to get a VB code through which I can encrypt and decrypt a string using a Key.

    Regards, Pavas ----------------------- [http://longjump.com/\] Dynamic business applications that manage and coordinate teams and information -----------------------

    A O S 3 Replies Last reply
    0
    • M mpavas

      Hello, I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa. I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails. Please help to get a VB code through which I can encrypt and decrypt a string using a Key.

      Regards, Pavas ----------------------- [http://longjump.com/\] Dynamic business applications that manage and coordinate teams and information -----------------------

      A Offline
      A Offline
      AliAmjad
      wrote on last edited by
      #2

      You should look at System.Security.Cryptography Namespace which contains a bunch of classes use one which suits your need.

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      1 Reply Last reply
      0
      • M mpavas

        Hello, I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa. I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails. Please help to get a VB code through which I can encrypt and decrypt a string using a Key.

        Regards, Pavas ----------------------- [http://longjump.com/\] Dynamic business applications that manage and coordinate teams and information -----------------------

        O Offline
        O Offline
        Ocean47
        wrote on last edited by
        #3

        This is very simple but it works! Public Class CL_EnCrypt Private sPsw As String = "XAN4519CEAN4719" Private sBox(255) As String Private sKey(255) As String Public Property Password() As String Get Return sPsw End Get Set(ByVal sVal As String) sPsw = sVal End Set End Property Public Function DeCrypt(ByVal sWord As String) As String If sPsw = "" Then MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set") Return "" End If Return EnDeCrypt(sWord) End Function Public Function EnCrypt(ByVal sWord As String) As String If sPsw = "" Then MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set") Return "" End If Return EnDeCrypt(sWord) End Function Private Sub RC4Initialize() Dim sSwap As String = "" Dim A, B As Integer Try For A = 0 To 255 sKey(A) = Asc(Mid$(sPsw, (A Mod sPsw.Length) + 1, 1)) sBox(A) = A Next B = 0 For A = 0 To 255 B = (B + sBox(A) + sKey(A)) Mod 256 sSwap = sBox(A) sBox(A) = sBox(B) sBox(B) = sSwap Next Catch ex As Exception MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End Sub Private Function EnDeCrypt(ByVal sPlainTxt As String) As String 'This routine does all the work. Call it both to ENcrypt and to DEcrypt your data. Dim A, I, J, K As Integer Dim sCipherBy, sCipher, sTemp As String Try sCipherBy = "" sCipher = "" sTemp = "" I = 0 J = 0 RC4Initialize() For A = 1 To sPlainTxt.Length I = (I + 1) Mod 256 J = (J + sBox(I)) Mod 256 sTemp = sBox(I) sBox(I) = sBox(J) sBox(J) = sTemp K = sBox((sBox(I) + sBox(J)) Mod 256) sCipherBy = Asc(Mid$(sPlainTxt, A, 1)) Xor K sCipher = sCipher + Chr(sCipherBy) Next Return sCipher Catch ex As Exception MessageBox.Show("Encription Error - "

        M 1 Reply Last reply
        0
        • O Ocean47

          This is very simple but it works! Public Class CL_EnCrypt Private sPsw As String = "XAN4519CEAN4719" Private sBox(255) As String Private sKey(255) As String Public Property Password() As String Get Return sPsw End Get Set(ByVal sVal As String) sPsw = sVal End Set End Property Public Function DeCrypt(ByVal sWord As String) As String If sPsw = "" Then MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set") Return "" End If Return EnDeCrypt(sWord) End Function Public Function EnCrypt(ByVal sWord As String) As String If sPsw = "" Then MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set") Return "" End If Return EnDeCrypt(sWord) End Function Private Sub RC4Initialize() Dim sSwap As String = "" Dim A, B As Integer Try For A = 0 To 255 sKey(A) = Asc(Mid$(sPsw, (A Mod sPsw.Length) + 1, 1)) sBox(A) = A Next B = 0 For A = 0 To 255 B = (B + sBox(A) + sKey(A)) Mod 256 sSwap = sBox(A) sBox(A) = sBox(B) sBox(B) = sSwap Next Catch ex As Exception MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End Sub Private Function EnDeCrypt(ByVal sPlainTxt As String) As String 'This routine does all the work. Call it both to ENcrypt and to DEcrypt your data. Dim A, I, J, K As Integer Dim sCipherBy, sCipher, sTemp As String Try sCipherBy = "" sCipher = "" sTemp = "" I = 0 J = 0 RC4Initialize() For A = 1 To sPlainTxt.Length I = (I + 1) Mod 256 J = (J + sBox(I)) Mod 256 sTemp = sBox(I) sBox(I) = sBox(J) sBox(J) = sTemp K = sBox((sBox(I) + sBox(J)) Mod 256) sCipherBy = Asc(Mid$(sPlainTxt, A, 1)) Xor K sCipher = sCipher + Chr(sCipherBy) Next Return sCipher Catch ex As Exception MessageBox.Show("Encription Error - "

          M Offline
          M Offline
          mpavas
          wrote on last edited by
          #4

          Thanks for the reply, But I need to use the code in VB and .NET so it should work on both ASP and ASP.NET. Hence I am looking for a code that is in VB and it has forward compatability. Backward compatability gives issue in Windows 2003 server. So i want some tuhing with forward compatability

          Regards, Pavas ----------------------- [http://longjump.com/\] Dynamic business applications that manage and coordinate teams and information -----------------------

          1 Reply Last reply
          0
          • M mpavas

            Hello, I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa. I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails. Please help to get a VB code through which I can encrypt and decrypt a string using a Key.

            Regards, Pavas ----------------------- [http://longjump.com/\] Dynamic business applications that manage and coordinate teams and information -----------------------

            S Offline
            S Offline
            Steven J Jowett
            wrote on last edited by
            #5

            Below is an encryption/decryption class I have written and use. To Encrypt, pass the the encrypt method the text to encrypt and an encryption key. As a result a string is returned with the encrypted text. To decrypt pass the encrypted text to the decrypt method along with the original encrytion key and as a result you should now have the original text returned by the method. Public Class Cryptography Public Shared Function Encrypt(ByVal Text As String, ByVal Key As String) As String Dim sEncrypted As String = "" Dim iKey As Integer = 0 If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required") For iChar As Integer = 0 To Text.Trim.Length - 1 Dim iTextChar As Integer = Asc(Text.Substring(iChar, 1)) Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1)) Dim iCharacterIndex As Integer = iTextChar + iKeyChar + iChar While iCharacterIndex > 255 iCharacterIndex = iCharacterIndex - 255 End While sEncrypted &= Chr(iCharacterIndex) iKey += 1 If iKey > (Key.Trim.Length - 1) Then iKey = 0 Next Return sEncrypted End Function Public Shared Function Decrypt(ByVal EncryptedText As String, ByVal Key As String) As String Dim sDecrypted As String = "" Dim iKey As Integer = 0 If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required") For iChar As Integer = 0 To EncryptedText.Trim.Length - 1 Dim iTextChar As Integer = Asc(EncryptedText.Substring(iChar, 1)) Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1)) Dim iCharacterIndex As Integer = iTextChar - iKeyChar - iChar While iCharacterIndex < 1 iCharacterIndex = iCharacterIndex + 255 End While sDecrypted &= Chr(iCharacterIndex) iKey += 1 If iKey > (Key.Trim.Length - 1) Then iKey = 0 Next Return sDecrypted End Function End Class Regards

            Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

            M 1 Reply Last reply
            0
            • S Steven J Jowett

              Below is an encryption/decryption class I have written and use. To Encrypt, pass the the encrypt method the text to encrypt and an encryption key. As a result a string is returned with the encrypted text. To decrypt pass the encrypted text to the decrypt method along with the original encrytion key and as a result you should now have the original text returned by the method. Public Class Cryptography Public Shared Function Encrypt(ByVal Text As String, ByVal Key As String) As String Dim sEncrypted As String = "" Dim iKey As Integer = 0 If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required") For iChar As Integer = 0 To Text.Trim.Length - 1 Dim iTextChar As Integer = Asc(Text.Substring(iChar, 1)) Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1)) Dim iCharacterIndex As Integer = iTextChar + iKeyChar + iChar While iCharacterIndex > 255 iCharacterIndex = iCharacterIndex - 255 End While sEncrypted &= Chr(iCharacterIndex) iKey += 1 If iKey > (Key.Trim.Length - 1) Then iKey = 0 Next Return sEncrypted End Function Public Shared Function Decrypt(ByVal EncryptedText As String, ByVal Key As String) As String Dim sDecrypted As String = "" Dim iKey As Integer = 0 If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required") For iChar As Integer = 0 To EncryptedText.Trim.Length - 1 Dim iTextChar As Integer = Asc(EncryptedText.Substring(iChar, 1)) Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1)) Dim iCharacterIndex As Integer = iTextChar - iKeyChar - iChar While iCharacterIndex < 1 iCharacterIndex = iCharacterIndex + 255 End While sDecrypted &= Chr(iCharacterIndex) iKey += 1 If iKey > (Key.Trim.Length - 1) Then iKey = 0 Next Return sDecrypted End Function End Class Regards

              Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

              M Offline
              M Offline
              Mark Churchill
              wrote on last edited by
              #6

              Hi Steve, I strongly recommend you take a look at the System.Security.Cryptography namespace. "Homebrew" cryptographic algorithms are almost never secure, and are often vulnerable to the most trivial of cryptanalysis. If you need to protect data then pick a reputable algorithm.

              Mark Churchill Director Dunn & Churchill Diamond Binding: Zero to Data Layer in 3 mins

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups