DES Decryption of XML-file

Posted on 2007-07-28
Medium Priority
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
  • 2

Expert Comment

ID: 19599168
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

ID: 19617837
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

ID: 19619474
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

Accepted Solution

Computer101 earned 0 total points
ID: 19815883
PAQed with points refunded (200)

EE Admin

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
When you put your credit card number into a website for an online transaction, surely you know to look for signs of a secure website such as the padlock icon in the web browser or the green address bar.  This is one way to protect yourself from oth…
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…
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 …
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

571 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