|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Article Discussion: String Encryption With Visual Basic .NET
String Encryption With Visual Basic .NET If you have any questions or comments about this article then please post them here.
You can read the article here . |
|
#2
|
|||
|
|||
|
Hopefully someone can help me with this.
The encryption is working fine, but when I try to decrypt and get an error . See Attached Image. Basically, when I encrypt, I display the encrypted text in a text box. However when I try to decrypt, I read from the textbox, covert the string to bytearray and call the Decrypt Function in the TripleDES class. The decryption is not working though. Please see the error attached as a Jpeg. Here is the code for decryption: Private Sub btnDecrypt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click Dim utf8encoder As UTF8Encoding = New UTF8Encoding Dim EncryptedText As String Dim EncryptedByte() As Byte Dim Decrypted As String EncryptedText = txtText.Text 'change the encrypted text to byte array EncryptedByte = utf8encoder.GetBytes(EncryptedText) Dim tdes As New TripleDES Decrypted = tdes.Decrypt(EncryptedByte) txtText.Text = Decrypted End Sub |
|
#3
|
|||
|
|||
|
Forgot to attache the Image.
Here it is: |
|
#4
|
|||
|
|||
|
I'm having the same problem. Did anyone figure it out yet? It fails on the following line of code with the following error message.
Line of Code: cryptStream.FlushFinalBlock(); Error Message: Length of the data to decrypt is invalid. |
|
#5
|
|||
|
|||
|
Corruption (I think)
I get a very strange phenominon.
I encrypt a string, write it to a file, read it back again and decrypt it works perfectly. If I restart IIS, or the Web server is rebooted and I try and decrypt the string from the file the first few characters of the string appear as rubbish ... Something that should be "Hello there how are you" would come back as "#I+j| are you" Can anyone help? |
|
#6
|
|||
|
|||
|
I had similar problems...
I was trying to encrypt the text in a textbox, place the encrypted text in the source textbox and then decrypt it back. After looking at the original encrypted byte() returned from the encryption algorithm, and the newly created byte() from the encrypted text in the textbox (they should be the same), I noticed that they were of different lengths. So I started playing with different encode/decode schemes. Finally came up with something that works (Cant guarentee it tho - since I don't know exactly why unicoding works and utf8 encoding doesn't.) Hope this helps or at least points you in the right direction. Heres the code for my decrypt / encrypt buttons Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim unicoder As UnicodeEncoding = New UnicodeEncoding() Dim EncryptedBytes As Byte() = unicoder.GetBytes(TextBox1.Text) Dim x As New TripleDES() TextBox1.Text = x.Decrypt(EncryptedBytes) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim x As New TripleDES() b_encoded = x.Encrypt(TextBox1.Text) Dim myUnicode As UnicodeEncoding = New UnicodeEncoding() TextBox1.Text = myUnicode.GetChars(b_encoded) End Sub |
|
#7
|
|||
|
|||
|
This seems to be the problem:
cryptStream.Write(inputInBytes, 0, (inputInBytes.Length - 1)) This should be: cryptStream.Write(inputInBytes, 0, inputInBytes.Length) |
|
#8
|
|||
|
|||
|
I was causing myself problems because I had set a length on the SPROC parameter I used to pass the encrypted CC number into the database. Look out for this. The field in the table was defined as varbinary(100), but my parameter was varbinary(16). Make sure you're not truncating the data like this...I believe the field and the parameter should be at least (24).
|
|
#9
|
|||
|
|||
|
Nevermind my post, I wasn't paying attention, it's Monday.
I am getting a 'System.TextImports' cannot be found and End of statement expected on System.Security.Cryptography. Please help! |
|
#10
|
|||
|
|||
|
String Encryption using VB.Net
I’m using the encryption and decryption methods from your article http://www.devarticles.com/c/a/VB.Net/String-Encryption-With-Visual-Basic-.NET/5/ published in devarticles.
I have developed a sample web application for password encryption.It encrypts the password and stores it into SQl Server 2000 DB. When user enters the credentials and log in it decrypts the password and checks if it is correct. Everyting works fine in my system. But if I create a web folder in another system (eg . a Server) move the Aspx files and the dlls to that sytem , it throws me an error when I try to pass the drow item to the decrypt function. Error message is “Specified Cast is not Valid”. I tried to use CTYPE to convert the dr item into byte() but it didn’t help. I’m using the following method Try Dim sqlapt As New SqlDataAdapter("select password from Resource where ResourceId=" + user, sqlConn) Dim Pass As String Dim dtab As New DataSet sqlapt.Fill(dtab) This line is throwing an error saying “Specified cast is not valid.” Dim dr As DataRow Dim TDES As New TripleDES For Each dr In dtab.Tables(0).Rows Pass = TDES.Decrypt(dr.Item("password")) Next Return Pass Catch ex As Exception CommonFunc.RaiseError(ex.Message) Finally sqlConn.Close() End Try Please help me out in resolving this. Thank you, |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Article Discussion: String Encryption With Visual Basic .NET |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|