954,190 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to create SHA1 Encryption program

How do I go about creating a windows application that converts strings to sha1 encrypted? All I want this program to do is have a user type in their password, click a command button "Convert" and have a label come up with the now SHA1 encrypted string. NOTE: THis is just for my own personal use, I will be in no way distributing or selling this program.

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

Ok, I will bite. What is SHA1 encryption?

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

SHA1 is an algorithm (Secure Hash Algorithm version 1.0) for encrpyting strings.

http://www.w3.org/PICS/DSig/SHA1_1_0.html happy reading dude. :)

Slade

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

:eek:

Wow, that is some reading.

:o

From a quick glance, I am guessing you will need to use RegEx for managing Regular Expressions.

Not sure I can be much help? :cry: Anyone else? Tekmaven?

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

it's ok, my supervisor is teaching me how to use crypto stuff. I will tell you more later.

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

Slade - I was just surfing around and found this site on SHA1 Encryption. Hope this helps!
:lol:
SHA1 Encryption Program

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

Thanks! My hardware should be arriving this week which means an article on forms authentication is due.

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

I can't understand why my code wont work. Check it out.

Imports SHA1_Encryption 
Imports System.Security.Cryptography
 
PublicClass Form1 
Inherits System.Windows.Forms.Form
 
(Windows for designer generated code)
PublicFunction ComputeHashValue(ByVal data() AsByte) AsByte() 
Dim hashAlg As SHA1 = SHA1.Create() 
Dim hashvalue() AsByte = hashAlg.ComputeHash(data) 
Return hashvalue 
EndFunction
 
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
Dim test AsByte() 
test = ComputeHashValue(Encoding.ASCII.Text(TextBox1.Text)) 
EndSub 
EndClass



The encoding part wont work and when I hover over it it says. "Name 'Encoding' is not declared." any ideas? Maybe I'm missing a library reference?

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

OK I would still like to get the windows encryption working (above) but I have finished a web application one for now:

Imports System.Web.Security

PrivateSub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim encpass AsString = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "sha1")
lblResult.Text = encpass.ToString()
EndSub
Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

No sure, but give me a chance to look at it tomorrow morning. :D

By the way, not to change the topic, how did you get the code to come out color coded when posting it here??

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

lol well I copied and pasted it from vs .net, but I've done it before using this rich text editor :D

Slade
Practically a Master Poster
633 posts since Mar 2004
Reputation Points: 115
Solved Threads: 7
 

try
test = ComputeHashValue(System.Text.Encoding.ASCII.GetBytes(TextBox1.Text))

esalkin
Newbie Poster
1 post since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

I just finished writing a SHA1 digester for Visual Basic 6. We needed this as a plug in for calculating the Psuedo-ESN in our cell phone database (KWC).

Hope it helps!

jt :eek:

http://www.tayloredge.com/utilities/vbapps/SHA1_VBSource.txt
http://www.tayloredge.com/utilities/vbapps/iSHA1.e_e

taylorjpt
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

public static string SHA1(string password)
{
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try
{
System.Security.Cryptography.SHA1CryptoServiceProvider cryptHandler;

cryptHandler = new System.Security.Cryptography.SHA1CryptoServiceProvider();

byte[] hash = cryptHandler.ComputeHash (textBytes);

string ret = "";

foreach (byte a in hash)
{
ret += a.ToString("x2");
}
return ret ;
}
catch
{
throw;
}
}

sembtest
Newbie Poster
1 post since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

I really didn't want to just spit out the answer, but wanted for my own entertainment to write the digester itself.

jt

taylorjpt
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You