choosechrist 0 Newbie Poster

I create an xml file on startup in my application which contains the connection string of the database.

Dim contactDoc As XDocument = <?xml version="1.0"?>
                                      <database server=<%= TextBox1.Text %> name=<%= TextBox4.Text %> userid=<%= TextBox2.Text %> password=<%= TextBox3.Text %>>
                                      </database>
        Dim str1 As String
        str1 = Application.StartupPath
        contactDoc.Save((str1 + "\data.xml"))
      
        MsgBox("Created")
        Me.Close()

the problem is..i want to encrypt it..but im new to this concept and although i found various algorithms online i have no clue how to implement it to the above code.this is one i'm using.

Public Class CryptoZ
        Private Shared DES As New TripleDESCryptoServiceProvider
        Private Shared MD5 As New MD5CryptoServiceProvider

        Public Shared Function MD5Hash(ByVal value As String) As Byte()
            Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
        End Function

        Public Shared Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
            DES.Key = MD5Hash(key)
            DES.Mode = CipherMode.ECB
            Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)
            Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
        End Function

        Public Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String
            Try
                DES.Key = MD5Hash(key)
                DES.Mode = CipherMode.ECB
                Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)
                Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
            Catch
                MessageBox.Show("Wrong Key Number, decryption not available!")
                Return Nothing
            End Try

        End Function

    End Class
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.