Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 14th, 2002, 07:06 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
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 .

Reply With Quote
  #2  
Old May 11th, 2003, 01:42 PM
njems njems is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 njems User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Getting an error!

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

Reply With Quote
  #3  
Old May 11th, 2003, 01:42 PM
njems njems is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 njems User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Forgot to attache the Image.
Here it is:
Attached Images
File Type: jpg errormsg.jpg (15.2 KB, 1375 views)

Reply With Quote
  #4  
Old June 19th, 2003, 09:18 AM
ItsMe ItsMe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 1 ItsMe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old September 17th, 2003, 04:04 AM
benjilloyd benjilloyd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 benjilloyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #6  
Old February 17th, 2004, 12:40 PM
WmDallas WmDallas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 WmDallas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Encoders

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

Reply With Quote
  #7  
Old July 22nd, 2004, 02:24 AM
RikeR RikeR is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 RikeR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This seems to be the problem:
cryptStream.Write(inputInBytes, 0, (inputInBytes.Length - 1))

This should be:
cryptStream.Write(inputInBytes, 0, inputInBytes.Length)

Reply With Quote
  #8  
Old January 4th, 2005, 09:16 PM
chlock chlock is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 chlock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 0
Exclamation Watch out for this

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).

Reply With Quote
  #9  
Old April 25th, 2005, 11:41 AM
stsong stsong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 stsong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 35 sec
Reputation Power: 0
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!

Reply With Quote
  #10  
Old July 10th, 2006, 04:30 AM
pradee pradee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 1 pradee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 42 sec
Reputation Power: 0
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,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: String Encryption With Visual Basic .NET


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap