Encrypt and decrypt a file using a DES algorithm

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 http://www.vb-helper.com/howto_net_des_file.html
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 18
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
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.
0
 
jmaggio322Commented:
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
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
So...
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  (?)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
jmaggio322
I dynamically creates this xml file...The encrypt option is unavailiable....
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
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

0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
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
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
How do you now the file is encrypted  if the name is the same for both the decrypted and encrypted version?
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotAuthor Commented:
TheHiTechCoach thank you for your post...
Already got it by CodeCruiser's Guideline..
Your comment is also helpfull that needs less actions..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.