• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

DES Decryption of XML-file

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.
  • 2
1 Solution
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
KrazzAuthor Commented:
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
KrazzAuthor Commented:
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
PAQed with points refunded (200)

EE Admin
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now