Solved

Help with decrypting file using vb.net

Posted on 2014-10-24
4
121 Views
Last Modified: 2014-10-25
Hi,

How do I modify the code to only decrypt \Data\LinkFiles\LinkFinal.xml instead of all xml files in the folder?

For Each File In Directory.GetFiles(Application.StartupPath & "\Data\LinkFiles")

            Try
                fslinkBEL = New System.IO.FileStream(File, IO.FileMode.Open)
                dtsetlinkBEL = New DataSet
                dtsetlinkBEL.ReadXml(fslinkBEL)
                fslinkBEL.Close()
                Dim sec As New Security
                For t As Integer = 0 To dtsetlinkBEL.Tables.Count - 1
                    For i As Integer = 0 To dtsetlinkBEL.Tables(t).Rows.Count - 1
                        For j As Integer = 0 To dtsetlinkBEL.Tables(t).Columns.Count - 1
                            If Not IsDBNull(dtsetlinkBEL.Tables(t).Rows(i).Item(j)) Then
                                'dtsetlinkBEL.Tables(t).Rows(i).Item(j) = sec.psEncrypt(dtsetlinkBEL.Tables(t).Rows(i).Item(j))
                                dtsetlinkBEL.Tables(t).Rows(i).Item(j) = sec.psDecrypt(dtsetlinkBEL.Tables(t).Rows(i).Item(j))
                            End If
                        Next
                    Next
                    dtsetlinkBEL.WriteXml(File)
                Next
            Catch
                MsgBox(Err.Description & "FileName  " & File)
            End Try
        Next
        MsgBox("All Files Decrypted")

Open in new window

0
Comment
Question by:vcharles
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40403566
You can remove the loop code (lines 1,2 and 23) and insert this line at line 1:
Dim File As String = Application.StartupPath & "Data\LinkFiles\LinkFinal.xml"

Open in new window

The try/catch block code remains the same. I just initialize File variable with your requested value.
0
 

Author Comment

by:vcharles
ID: 40403881
Hi,

Thanks for the code, how do you check to see if the file is encrypted before you attempt to decrypt it?

V.
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40404277
Regarding post question, the short answer is : NO.
If a code can determine this, it could mean that the encryption algorithm was broken. The goal of the encryption is to produce a file that looks like a random chunk of data.
Having said that you could add an extra node element to your xml, this element should store a value that your program reads and determine whether the file contains encrypted/decrypted info.
0
 

Author Comment

by:vcharles
ID: 40404342
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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