I am trying to make a web browser that encrypts the url and decrypts and goes to said url.
The problem is that everything else works but as soon as I try to go to the url using webbrowser.navigate() it comes up with this error:
"Error HRESULT E_FAIL has been returned from a call to a COM component."
It decrypts the url correctly because I used a separate text box to run the exact same algorithm (with the exception that its output is shown in the textbox).
If it helps here is the code:
In bold is where the error comes up. Could someone tell me how to fix this and where I went wrong?
The problem is that everything else works but as soon as I try to go to the url using webbrowser.navigate() it comes up with this error:
"Error HRESULT E_FAIL has been returned from a call to a COM component."
It decrypts the url correctly because I used a separate text box to run the exact same algorithm (with the exception that its output is shown in the textbox).
If it helps here is the code:
Code:
Public Class Form1
Const versioncode = "tst."
Dim length As Integer
Dim url As String
Sub encrypt()
url = TextBox2.Text
Dim newurl As String
length = Len(url)
Dim lenchar(length), newchar(length), dechar(length) As Char
length = Len(url)
For counter = 1 To length
lenchar(counter) = Mid(url, counter, 1) 'splits up url into chars
Next
For counter2 = 1 To length
newchar(counter2) = ChrW(Asc(lenchar(counter2)) Xor 128) 'changes char value
Next
newurl = versioncode
For counter4 = 1 To length
newurl = newurl + newchar(counter4)
Next
length = Len(newurl)
TextBox3.Text = newurl
End Sub 'this encrypts the url .
Sub decrypt(ByVal url As String)
Dim enurl As String = TextBox1.Text
Dim sinchar(length), oldchar(length) As Char
Dim oldurl As String = ""
Dim realurl As String = Replace(enurl, versioncode, "")
length = Len(enurl)
For counter = 1 To length
sinchar(counter) = Mid(realurl, counter, 1)
oldchar(counter) = ChrW(Asc(sinchar(counter)) Xor 128) 'gets original characters back
Next
For counter2 = 1 To length
oldurl = oldurl + oldchar(counter2) 'puts all chars into a single string so that it can be used as a url
Next
WebBrowser1.Navigate(oldurl)
End Sub 'this decrypts the url although does not make the actual url visible.
Sub decrypt_check()
Dim enurl As String = TextBox3.Text
Dim sinchar(length), oldchar(length) As Char
Dim oldurl As String = ""
Dim realurl As String = Replace(enurl, versioncode, "")
length = Len(enurl)
For counter = 1 To length
sinchar(counter) = Mid(realurl, counter, 1)
oldchar(counter) = ChrW(Asc(sinchar(counter)) Xor 128)
Next
For counter2 = 1 To length
oldurl = oldurl + oldchar(counter2) 'puts all chars into a single string so that it can be used as a url
Next
TextBox4.Text = oldurl
End Sub 'Ensures that the decryption is working
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim url As String
url = textbox1.Text
If Microsoft.VisualBasic.Left(url, 4) = versioncode Then 'decides whether or not the url needs to be decrypted or not
decrypt(url)
Else
WebBrowser1.Navigate(TextBox1.Text)
End If
End Sub 'go button
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub 'web browser
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
encrypt()
decrypt_check()
End Sub 'convert button
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
End Sub
End Class