Results 1 to 19 of 19

Thread: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    [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
    Attached Files Attached Files
    Last edited by knxrb; Sep 7th, 2007 at 11:19 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  3. #3
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

    ummmm...that didn't encrypt my file...it just renames it
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

    Reply to Hack: OoOops! Sorry, didn't know!

  5. #5

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    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.

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    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.

  8. #8
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  10. #10
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

    This thread should be removed from the codebank, since it is useless...

  11. #11
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  13. #13
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

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

  14. #14

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    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

  15. #15
    New Member
    Join Date
    Sep 2004
    Location
    Serbia
    Posts
    6

    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!

  16. #16

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

    I use renamefile, copyfile, movefile, downloadfile, uploadfile etc. all the time.

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [VB 2005] Easy File Encryption/Decryption - Only 2 Lines Of Code!

    lol, u got any encryption code then?

  19. #19
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width