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.

Ok, I will bite. What is SHA1 encryption?

: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?

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

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

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

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?

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

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??

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

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

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;
    }
}

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

jt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.