Encryption
-
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 -----------------------
-
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 -----------------------
-
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 -----------------------
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 - "
-
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 - "
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 -----------------------
-
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 -----------------------
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
RegardsSteve 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'
-
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
RegardsSteve 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'
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