Question SHA1 Hash & B64 Encode Text Box

manix

Member
Joined
Aug 19, 2009
Messages
5
Programming Experience
1-3
Hello all,

I'm new to this forum and very excited to be here. I hope to learn as much as I can, and share my knowledge with you all as well :).

My question is:

I have been developing a small console applications with a very simple purpose.
To avoid a lengthy explanation I have included a screen shot to make it easier for everyone.

http://www.4rhymes.com/app1.jpg

As you can see, what I'm trying to do is allow a user to specify a username they want, followed by a password of their choice. Upon clicking "Encrypt Password", I want the program to hash the txtPassword string using SHA1 and then encode that using base 64. Once it has done so, clicking on "Write To File" will simply store both the username and password to an external file. I have no problem with the write button, but the encrypt button is giving me a very hard time. I would appreciate anyone's help!!

Here's what I got so far. I don't know if this is even remotely correct. But it's a start I guess.....

Dim myString As String = txtPassword.Text
Dim Data As Byte()

Data = Encoding.ASCII.GetBytes(myString)

Dim shaM As New SHA1Managed()
Dim resultHash As Byte() = shaM.ComputeHash(Data)

Dim resultHexString = txtPassword.Text
Dim b As Byte

For Each b In resultHash
resultHexString += Hex(b)
Next

Thank you all for your help! I really appreciate it!!
 
VB.NET:
Dim b64 As String = Convert.ToBase64String(resultHash)
 
Thanks for your reply John.

Sorry to look like such a dumbass, but what does that snippet of code do? Does it take the result of the SHA1 hashed string and encode it in base 64?

Thanks!
 
Also just as an example, here is the end result of an example password:

The password "badger", once hashed with SHA1 and encrypted with Base64 should translate to "ThmbShxAtJepX80c2JY1FzOEmUk=".

Thanks for your help everyone! I really appreciate it.
 
but what does that snippet of code do? Does it take the result of the SHA1 hashed string and encode it in base 64?
Convert.ToBase64String(byte()) converts to Base64 string the provided byte array. resultHash was were you stored the Sha1 hash byte array.
The password "badger", once hashed with SHA1 and encrypted with Base64 should translate to "ThmbShxAtJepX80c2JY1FzOEmUk=".
Yes, that is correct.
 
Thanks a lot John. So does that mean that I now use the variable b64 as the variable to be written to file. In other words, does the variable "b64" contained the SHA1 hashed and B64 encoded string of the password entered by the user? Thanks again!
 
Back
Top