[Vb] [C#] Sha1 hashing

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
9 posts Page 1 of 1
Contributors
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

[Vb] [C#] Sha1 hashing
smashapps
Hello,

I haven't seen any tutorials on this on Codenstuff well couldn't find any anyway. I was posting a tutorial on this because I thought it would be good to show how you can has text that can't be decrypted.

Unfortunately don't know much about cryptography and Sha1 CAN'T be decrypted but it can easily be brute forced.

Overview of Sha1

Sha stands for secure hash algorithm and sha1 is basically the version (sha0-sha3) and was published 1993. It is the most common hash function.

If you want to learn more about it just look it up.

Other interesting types of encryption include Symmetric encryption which is where we use an IV and a key which we use to Encrypt and Decrypt text and Asymmetric encryption is where We have a different Key and IV to encrypt and decrypt but it is recommended to use GenerateKey() and generateIV() each session.

With this tutorial we have a function called Sha1has and we call that with the text we want encrypted. We declare a new instance of the Sha1CryptoServiceProvider. We declare a byte and we set that to our string we're converting then we use our sha1 to compute the byte hash. Then we run a loop for every byte we find in our byte hash and we hash it :P then we output the encrypted text.

Visual Basic Code:
Code: Select all
Function Sha1hash(ByVal StringToEncrypt As String) As String
        Dim Sha1 As New Security.Cryptography.SHA1CryptoServiceProvider
        Dim b_ToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(StringToEncrypt)

        b_ToHash = Sha1.ComputeHash(b_ToHash)
        Dim HashedString As String = ""
        For Each b As Byte In b_ToHash
            HashedString += b.ToString("x2")
        Next

        txtOutput.Text = HashedString
        Return Nothing

    End Function
Send the text to be encrypted:
Code: Select all
Private Sub btnEncrypt_Click(sender As System.Object, e As System.EventArgs) Handles btnEncrypt.Click
        Sha1hash(txtEncrypt.Text)
    End Sub
C# Code:
Code: Select all
public string Sha1hash(string StringToEncrypt)
{
	System.Security.Cryptography.SHA1CryptoServiceProvider Sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
	byte[] b_ToHash = System.Text.Encoding.ASCII.GetBytes(StringToEncrypt);

	b_ToHash = Sha1.ComputeHash(b_ToHash);
	string HashedString = "";
	foreach (byte b in b_ToHash) {
		HashedString += b.ToString("x2");
	}

	txtOutput.Text = HashedString;
	return null;

}
Code: Select all
private void btnEncrypt_Click(System.Object sender, System.EventArgs e)
{
	Sha1hash(txtEncrypt.Text);
}
Above is the function we use (which I described). Sorry i didn't describe it very well it's a confusing subject.

To call out function I have two textboxes one is for the text to be encrypted and one is for the output. The output is named txtOutput and the text to be encrypted is named txtEncrypt.

We create a button called btnEncrypt and on the click event of the button we call the function and in brackets we give it the text we're encrypting. After we've clicked the button our hashed text will appear in the output.

Sha1Hash(txtEncrypt.Text)

I've zipped up the project if you want to download the code.

Image

I hope I've helped, thanks.
You do not have the required permissions to view the files attached to this post.
Last edited by smashapps on Sat Dec 05, 2015 11:21 am, edited 2 times in total.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: [Vb] [C#] Sha1 hashing
Shim
sha (secure hash algorithms but its not secure anymore lol)
  • SHA-0
    SHA-1
    SHA-2
    SHA-256
    SHA-384
    SHA-512
the best algorithms are
  • HAVAL
    RIPEMD-320
    Gost 64
    Whirlpool
nice tutorial tom :D
Find my programs on Softpedia
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: [Vb] [C#] Sha1 hashing
smashapps
I haven't heard of those algorithms before. I'll edit the post when I can to better explain a couple things too.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: [Vb] [C#] Sha1 hashing
benji_19994
Shim sha1 can be brute forced not decrypted -__-
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: [Vb] [C#] Sha1 hashing
Shim
benji_19994 wrote:
Shim sha1 can be brute forced not decrypted -__-
http://www.sha1.cz/
http://www.md5decrypter.co.uk/sha1-decrypt.aspx
http://www.stringfunction.com/sha1-decrypter.html

if the hash is already been cracked you could decrypt or something something
Find my programs on Softpedia
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: [Vb] [C#] Sha1 hashing
benji_19994
Isn't that funny i tried all of them with the hash sha1 ben and none of them online scanners guessed it
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: [Vb] [C#] Sha1 hashing
Shim
benji_19994 wrote:
Isn't that funny i tried all of them with the hash sha1 ben and none of them online scanners guessed it
as i said before if the hash was cracked by dictionary attack etc someone will add the decrypted text to the website so one when we go give a decrypt try if the hash matches the hash in the database it will show the decrypted text ............................................................
Find my programs on Softpedia
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: [Vb] [C#] Sha1 hashing
benji_19994
Well anyway as a programmer i try and make my programs secure so they cannot even get the hashed passwords
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: [Vb] [C#] Sha1 hashing
smashapps
Okay thanks for clarifying that I still thought it was a good tutorial to show people how to hash passwords.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
9 posts Page 1 of 1
Return to “Tutorials”