|
-
Dec 7th, 1999, 07:04 AM
#1
Thread Starter
Hyperactive Member
Hi there,
I'm looking for a way to encrypt my html files so that they can only be opened by the Web browser control on my form. I found this code (pasted by Aaron Young, I think - thank you Aaron!) on how to encrypt text files. It works for text files. I replaced 'Text1', as the code originally was, with WebBrowser1' - the name of my browser control, but it doesn't work.
Does anybody know how I can resolve my problem - encrypt my html files? I don't want people
to be able to open them in any browser - just mine.
Thanks for any help!
Private Sub Command1_Click()
'Open Encrypted File
Dim sText As String
Dim iFile As Integer
On Error GoTo Cancelled
With CommonDialog1
.CancelError = True
.Filter = "AY Encrypted|*.aye"
.ShowOpen
iFile = FreeFile
Open .FileName For Input As iFile
sText = Input(LOF(iFile), iFile)
Close iFile
End With
If Left(sText, 12) <> "AY Encrypted" Then
MsgBox "Not an AY Encrypted File Format"
Else
WebBrowser1 = DecryptText(Mid(sText, 13))
End If
Cancelled:
End Sub
Private Sub Command2_Click()
'Save Encrypted File
On Error GoTo Cancelled
With CommonDialog1
.CancelError = True
.Filter = "AY Encrypted|*.aye"
.ShowSave
iFile = FreeFile
Open .FileName For Output As iFile
Print #iFile, EncryptText(WebBrowser1);
Close iFile
End With
MsgBox "Saved"
Cancelled:
End Sub
Function EncryptText(ByVal sText As String) As String
Dim sKey As String
Dim iKey As Integer
Dim lPos As Long
Dim iChar As Integer
Randomize Timer
sKey = Right("000" & Hex(Int(Rnd(1) * 4095)), 3)
For lPos = 1 To Len(sText)
iChar = Asc(Mid$(sText, lPos, 1))
Mid$(sText, lPos, 1) = Chr(iChar + Val("&H" & Mid(sKey, iKey + 1, 1)))
iKey = (iKey + 1) Mod 3
Next
EncryptText = "AY Encrypted" & sText & Right(Space(20) & (Val("&H" & sKey) + Len(sText)), 20)
End Function
Function DecryptText(ByVal sText As String) As String
Dim sKey As String
Dim iKey As Integer
Dim lPos As Long
Dim iChar As Integer
sKey = Right("000" & Hex(Val(Right(sText, 20)) - (Len(sText) - 20)), 3)
For lPos = 1 To Len(sText) - 20
iChar = Asc(Mid$(sText, lPos, 1))
Mid$(sText, lPos, 1) = Chr(iChar - Val("&H" & Mid(sKey, iKey + 1, 1)))
iKey = (iKey + 1) Mod 3
Next
DecryptText = Left(sText, Len(sText) - 20)
End Function
-
Dec 7th, 1999, 07:20 AM
#2
You can't assign text to the web browser object like this:
WebBrowser1 = DecryptText(Mid(sText, 13))
What you have to do is to save the decrypted file to a temporary HTML file and use the Navigate method of the web browser object to open the file.
iFile = FreeFile
Open "c:\MyEncrypted.htm" For Output As #iFile
Print #iFile, DecryptText(Mid$(sText, 13))
Close #iFile
WebBrowser1.Navigate "c:\MyEncrypted.htm"
Good luck!
------------------
Joacim Andersson
[email protected]
[email protected]
www.YellowBlazer.com
-
Dec 7th, 1999, 04:27 PM
#3
Thread Starter
Hyperactive Member
Thanks Joacim, I'll give it a go!
-
Dec 7th, 1999, 09:27 PM
#4
New Member
Perhapsa a better way would be to directly access the webbrowser.document object. Here, you can directly manipulate the HTML text of the Webbrowser.Document object.
There is no local help (i.e. help files) for the extended objects in the Webbrowser control. To get started with these internal objects, go to http://msdn.microsoft.com/workshop/b.../reference.asp .
Have fun!
-
Dec 8th, 1999, 07:28 AM
#5
Hyperactive Member
May be there is a simpler/better way: Embed your code into your .exe:
-------
WebBrowser1.Navigate2 "about:blank"
'Then insert your own HTML code:
Dim MyHTML As String
MyHTML = "Your HMTL Code Here"
WebBrowser1.Document.Body.Innerhtml = MyHTML
-------
About.blank is the default page when your browser can't find a server. You can replace there a specially made page, with just usual <html> and <body> tags, as Innerhtml method will insert your code between those "body tags", so you can define your background, etc.
"Your HMTL Code Here" means your own page, i.e. all your code between <body> and </body>
P.D. I'd better be fair mentioning the source:
http://www.vbsquare.com/code/230.htm
-
Dec 9th, 1999, 04:17 AM
#6
Thread Starter
Hyperactive Member
Thanks for your help, everybody.
Juan Carlos,
I had thought of your idea, but the problem is that I have links between the .htm files that are encrypted. Maybe that's doesn't matter too much - I'll have to study it in more detail.
How about this idea? I already know how to encrypt a text file. When the user clicks the 'Open' button, they think they're actually opening the html file into the browser control. But what they're actually doing is opening the encrypted text file into an invisible textbox - which turns out decrypted. Then, I'll instruct the webbrowser to open whatever text is in the textbox - on the text_change event or something. Does anyone know the code for doing this last part?
In any case, thanks a lot!
-
Dec 9th, 1999, 09:37 AM
#7
Hyperactive Member
Think twice.
With the InnerHTML method:
* You don't have to supply extra files
* Your user won't be able to see the code even if he/she right clicks on the browser (all they will see is the code for the about:blank page or your specially made page, with just bgcolor or background img)
* I don't see any problems including links. You can even use internal links within a single page ("a name" method)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|