Solved

Help with decrypting file using vb.net

Posted on 2014-10-24
4
116 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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