DES Decryption of XML-file

Posted on 2007-07-28
Last Modified: 2013-11-07
I have an XML file that is encrypted with DES encryption. I don't have any encryption knowledge so I basically only need enough information to get going ont he correct track here.

The XML file is encrypted and I do have the key for it, I just don't know how to write a program to decrypt it. All the examples I have found always include a KEY and an IV. As I said, I have the key, but what is the IV and how do I figure it out? Or is there a way around this where I don't need the IV?

Ohhh, and of course I would know how to encrypt a file back using the same type of code (not needing to know the IV).

I would prefer any code examples in VB.Net if possible.
Question by:Krazz
    LVL 1

    Expert Comment

    The Initialization Vector (IV) serves as a seed that is used to encrypt and decrypt the first block of bytes. This ensures that no two blocks of data produce the same block of encrypted text.

    Try using same IV and Key to decrypt.

    Imports System.Security
    Imports System.Security.Cryptography
    Imports System.Text
    Imports System.IO

    Public Class Tester
        Public Shared Sub Main
                Dim myDESProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()

                myDESProvider.Key = ASCIIEncoding.ASCII.GetBytes("12345678")
                myDESProvider.IV = ASCIIEncoding.ASCII.GetBytes("12345678")

                Dim DecryptedFile As FileStream = New FileStream("testDes.txt", FileMode.Open, FileAccess.Read)
                Dim myICryptoTransform As ICryptoTransform = myDESProvider.CreateDecryptor(myDESProvider.Key, myDESProvider.IV)
                Dim myCryptoStream As CryptoStream = New CryptoStream(DecryptedFile, myICryptoTransform, CryptoStreamMode.Read)

                Dim myDecStreamReader As New StreamReader(myCryptoStream)
                Dim myDecStreamWriter As New StreamWriter("test.txt")


            Catch ex As Exception

            End Try
        End Sub
    End Class

    Author Comment

    Thanks for your help. I have tried this before but the key is too long for this approach. The key is 45 characters long if that makes any difference?!

    I also get an exception that says exactly this:
    System.ArgumentException: The provided key size is not allowed for this algoritm.
       vid System.Security.Cryptography.DES.set_Key(Byte[] value)
       vid DESDecrypt.Tester.Main() i D:\Private\Dokument\Visual Studio 2005\Projects\DESDecrypt\DESDecrypt\Class1.vb:rad 11

    Author Comment

    I found a sollution that works.

    Imports System.Security.Cryptography
    Imports System.IO

    Public Class XmlDecrypter
        Public Shared Sub Decrypt(ByVal FileIn As String, ByVal FileOut As String, ByVal DecryptKey As String)
            Dim fs As FileStream = Nothing
            Dim cs As CryptoStream = Nothing
            Dim ds As DataSet = New DataSet
            Dim buffer2 As Byte() = Nothing
            Dim bytes As New PasswordDeriveBytes(DecryptKey, Nothing)
            Dim rgbIV As Byte() = New Byte(8 - 1) {}
            Dim provider As New DESCryptoServiceProvider

            buffer2 = bytes.CryptDeriveKey("DES", "MD5", 0, rgbIV)

            fs = New FileStream(FileIn, FileMode.Open, FileAccess.Read, FileShare.None)

            cs = New CryptoStream(fs, provider.CreateDecryptor(buffer2, rgbIV), CryptoStreamMode.Read)

        End Sub
    End Class
    LVL 1

    Accepted Solution

    PAQed with points refunded (200)

    EE Admin

    Featured Post

    Highfive Gives IT Their Time Back

    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

    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    A few customers have recently asked my thoughts on Password Managers.  As Security is a big part of our industry I was initially very hesitant and sceptical about giving a program all of my secret passwords.  But as I was getting asked about them mo…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now