Encrypt and decrypt a file using a DES algorithm

Posted on 2011-04-21
Last Modified: 2012-05-11
I am learning about Encryption and Decryption in VB.Net this time...
i found several articles and tutorials.
The one i use for sample purposes is
The example creates an output file that is encrypted..although the original file can be accessed..
I need some help here...i want my original file to be encrypted...
    LVL 83

    Accepted Solution

    I think you have to move the original file to a temp location and then recreate it at original location. The temp file can then be deleted.
    LVL 4

    Expert Comment

    how about you just enrypt the original by either using the cipher command in a command prompt or encrypting it through the properties of the file. properties general tab advanced button and check encrypt this file
    LVL 18

    Author Comment

    by:John (Yiannis) Toutountzoglou
    1.i've created an XML file in C:\Sqvars.xml
    2.I have to move this file in temp directory
    The Following Code Creates a temp file in my temp directory

    Dim sTempFile As String = System.IO.Path.GetTempFileName()
            Dim fsTemp As New System.IO.FileStream(sTempFileName, IO.FileMode.Create)]

    Open in new window

    3.the output encrypt file should have the same name with my original one  (?)
    LVL 18

    Author Comment

    by:John (Yiannis) Toutountzoglou
    I dynamically creates this xml file...The encrypt option is unavailiable....
    LVL 18

    Author Comment

    by:John (Yiannis) Toutountzoglou
    Got it...
    1.i move the original file to a temp location
    2.I create encrypted File to my specific Location
    and i do the opposite when i need the data of the file....
       Dim FileToMove As String
                 Dim MoveLocation As String
                 Dim sTempFileName As String = System.IO.Path.GetTempFileName()
            FileToMove = "C:\SqVars.xml"
            MoveLocation = System.IO.Path.GetTempPath & "SqVars.xml"
            If System.IO.File.Exists(FileToMove) = True Then
                System.IO.File.Move(FileToMove, MoveLocation)
            End If 

    Open in new window

    LVL 21
    I would do this:

    1)  create the XML file as temp file with a temp name. Not the name you want
    2) encrypt  the temp file to a new fiel with the name you want.
    3) delete the temp file that is not encrypted
    LVL 21
    How do you now the file is encrypted  if the name is the same for both the decrypted and encrypted version?
    LVL 18

    Author Comment

    by:John (Yiannis) Toutountzoglou
    TheHiTechCoach thank you for your post...
    Already got it by CodeCruiser's Guideline..
    Your comment is also helpfull that needs less actions..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now