1 Attachment(s)
[VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Just thought of a way to encrypt files and decrypt them with only two lines of code:
Encrypt:
Code:
My.Computer.FileSystem.RenameFile(my.computer.filesystem.specialdirectories.mydocuments & "\text.txt", "text.enc")
This encrypts the file: "\text.txt" >>> "\text.enc"
You can have any extension you want as well. Just change the .enc extension.
Decrypt:
My.Computer.FileSystem.RenameFile(my.computer.filesystem.specialdirectories.mydocuments & "\text.enc", "text.txt")[/CODE]
This decrypts the file: "\text.enc" >>> "\text.txt"
If you wanna try it then try this code. It allows you to see the encryption.
Code:
My.Computer.FileSystem.RenameFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\text.enc", "text.txt")
msgbox"Decrypted"
My.Computer.FileSystem.RenameFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\text.txt", "text.enc")
msgbox"Encrypted"
1. Create "text.enc" file in your documents folder using notepad (or download from attachment).
2. When the first messagebox comes up go to your documents folder and you will see the file "text.txt"
3. Then when the 2nd messagebox comes up look in your documents again and you will see a "text.enc" file.
Hope It Helps Someone :)
-----
knxrb
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
As this is meant to be shared, it is more appropriate in the CodeBank.
Moved
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
ummmm...that didn't encrypt my file...it just renames it:confused:
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Reply to Hack: OoOops! Sorry, didn't know!
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Reply To Kebo: It makes the file unreadable. Nobody can come along and open your file and read it.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Quote:
Originally Posted by knxrb
Reply To Kebo: It makes the file unreadable. Nobody can come along and open your file and read it.
just changing a files extension doesn't make it unreadable......try opening the *.enc file in notepad
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
oh! on my app it downloads file from web server, decrypts it, reads it, encrypts it, then deletes it from comp. It not meant to stay on comp.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Quote:
Originally Posted by knxrb
oh! on my app it downloads file from web server, decrypts it, reads it, encrypts it, then deletes it from comp. It not meant to stay on comp.
The method you outlined does not have anything to do with encryption.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Exactly like Kebo said, changing a file's extension does not encrypt it. Encrytion means you actually encrypt the contents of the file.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
This thread should be removed from the codebank, since it is useless...
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
by changing the extension all it does is cause windows to pop the dialog asking what program you want to use to open it. This is in no way secure whatsoever as the contents of the file are exactly the same and readable with any test editor.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
Quote:
Originally Posted by nbrege
This thread should be removed from the codebank, since it is useless...
I would not go so far as to call it useless, but I would agree that it does have issues that need to be resolved, and therefore, is more fitting in the .NET Q&A section.
Moved Back
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
I just meant that it is useless as far as encrypting is concerned, since the method the OP presents does not actually do any encrypting/decrypting. I hope I did not offend anyone...
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
If you want then move my post. Can you all check my other 2 posts in the codebank and see what you think of those as well.
-----
knxrb
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
This is coolest way to "encrypt" data.:):) I used when I was 5.....
Does this My.Computer.FileSystem.RenameFile didn't mean anything to you? It very hard to start programming without knowing something like that..
Good luck!
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
I use renamefile, copyfile, movefile, downloadfile, uploadfile etc. all the time.
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
This is possibly the silliest thread I've ever read. Given that the name of the method is RenameFile why would you think that it would do anything other than rename the file? The file name extension has no effect whatsoever on the contents of a file. You can give any file any extension you like. The only thing that does is prevent you opening the file by double-clicking it in Windows Explorer. You can still use File->Open in the same app and the file will open in all its glory. Try it with your allegedly encrypted text file and you'll see that you can still open it in Notepad and see all the text it contains. Don't you suppose that a method that encrypted a file would have "encrypt" somewhere in the name?
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
lol, u got any encryption code then?
Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!
There's an entire namespace dedicated to cryptography in the .NET Framework.
http://search.msdn.microsoft.com/sea...y.cryptography