Hashing

Radiit

New member
Joined
Feb 27, 2007
Messages
4
Programming Experience
Beginner
How do you encrypt a string using DES and MD4 in vb.net 2003 or 2005
 
If you want to stay ultra secure and ahead of the game i would stop using DES, MD4 and even MD5 and they are becoming increasingly unstable. SHA-2 is a better bet and available in the framework. See this site for more details...

http://www.codeproject.com/useritems/GoodbyeMD5.asp
 
Ok, but I have a MD5 hashed file to recover. So I decided to write a VB program for it rather than getting ready made softwares. So, can I have the code for it?
 
Hashing is a one-way operation, you can't recover a hash, it's only used when possibly same input is hashed again to see if it match, like password checking.
 
DES Hash

VB.NET:
Imports System
Imports System.Text
Imports System.Security
Imports System.Security.Cryptography
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.Strings
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n As Byte() = System.Text.Encoding.ASCII.GetBytes("")
Dim u7 As Encoding = Encoding.UTF7
Dim desCrypto As DESCryptoServiceProvider = DESCryptoServiceProvider.Create()
Dim keyBytes() As Byte = u7.GetBytes(TextBox1.Text)
 
ReDim Preserve keyBytes(8 - 1)
ReDim Preserve n(8 - 1)
 
desCrypto.Key = keyBytes
desCrypto.IV = n
 
Dim pass() As Byte = _
System.Text.Encoding.ASCII.GetBytes(TextBox2.Text)
Dim ms As New System.IO.MemoryStream
Dim encStream As New CryptoStream(ms, _
desCrypto.CreateEncryptor(), _
System.Security.Cryptography.CryptoStreamMode.Write)
encStream.Write(pass, 0, pass.Length)
TextBox3.Text = BytesToHexString(ms.ToArray)
 
encStream.Flush()
encStream.FlushFinalBlock()
End Sub
 
Public Shared Function BytesToHexString(ByVal bytes As Byte()) As String
Dim hexString As StringBuilder = New StringBuilder(64)
Dim counter As Integer
 
For counter = 0 To bytes.Length - 1
hexString.Append(String.Format("{0:X2}", bytes(counter)))
Next
 
Return hexString.ToString()
End Function
End Class


For the above code I get the same hex string (DC22CC897735644B) when the
textbox2 is 12345678 and textbox1 is 2 or 3. I get the same repeated hex strings for 4 and 5, 6 and 7 and so on. Why is it like this and can somebody help in my coding?
 
Last edited by a moderator:
Does that really matter as long as you get same data back when you decrypt when using the same key?
 
Back
Top