Encryption issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to encrypt and decrypt an XML string. I have it encrypting
but decrypting is a problem, somehow the XML is getting all corrupted.

Any ideas?

Im saving the XML text to a byte[] and then encrypting that using DES, and
writing it to a file and the reverse for reading it back in.

Thanks
 
Can you post an example, and a little more detail about what is going
wrong?
 
I got it working, instead of storing as a binary file directly and using the
default CipherMode i now store as a base64string and use ECB so its the same
for the same keyusage.

I do get exceptions on keylenghts when i compute the MD5 hash on the key,
the key is 8 bytes as an example and hashed to 16 bytes.



Nicholas Paldino said:
Can you post an example, and a little more detail about what is going
wrong?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I am trying to encrypt and decrypt an XML string. I have it encrypting
but decrypting is a problem, somehow the XML is getting all corrupted.

Any ideas?

Im saving the XML text to a byte[] and then encrypting that using DES, and
writing it to a file and the reverse for reading it back in.

Thanks
 
I got it working, instead of storing as a binary file directly and using the
default CipherMode i now store as a base64string and use ECB so its the same
for the same keyusage.

I would recommend using CBC mode. ECB mode is more susceptible to
cryptanalysis. Feedback modes help obscure common patterns in the data.
Also, you might want to consider using an algorithm with a larger key. DES
is old-school encryption, has a weak key size, and is being replaced with
AES (which is basically the Rijndael algorithm for the block cipher part of
the spec).
Saving the XML to a common encoding (base64) probably fixed your real issue,
so again, consider going back to CBC mode. In addition, there may yet be a
descrepency between your encrypt/decrypt functions. It's hard to tell unless
you post the code.
I do get exceptions on keylenghts when i compute the MD5 hash on the key,
the key is 8 bytes as an example and hashed to 16 bytes.

Hashes always compute a fixed-length result reguardless of how much data you
feed them as input. MD5 always results in 16 bytes even if the input is
bigger or smaller.

-Rob Teixeira [MVP]
 
Back
Top