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