Solved

Help with decrypting file using vb.net

Posted on 2014-10-24
4
122 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

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 …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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