Encryption issue

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
 
N

Nicholas Paldino [.NET/C# MVP]

Can you post an example, and a little more detail about what is going
wrong?
 
G

Guest

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
 
R

Rob Teixeira [MVP]

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top