I need two methods one to encrypt and one to decrypt an xml file with a key= “hello world”,the key hello world should be used to encrypt and decrypt the xml file.These methods should work on all machines!!! Any encryption methods will do. XML File contents below:
<root>
<lic>
<number>19834209</number>
<expiry>02/02/2002</expiry>
</lic>
</root>
Can some give me a sample?The issue is the msdn sample encyptions make a xml file encypted but when I decrypt on another machine it doesn’t work.For example
I tried this sample:
How to: Encrypt XML Elements with Asymmetric Keys,
but here there is some kinda session and on another machine it says bad data phewf!
If you want the same key for encrypting and decrypting you should use a symmetric method (that’s the definition, really). Here’s the closest one to your sample (same source).
http://msdn.microsoft.com/en-us/library/sb7w85t6.aspx
The posted sample isn’t working because they aren’t using the same keys. Not only on different machines: running the program on the same machine twice should not work either (didn’t work for me), because they use different random keys every time.
try adding this code after creating your key:
Now the program is using the same key and initial vector, and Encrypt and Decrypt should work on all machines.
Also, consider renaming
keytoalgorithm, otherwise this is very misleading. I’d say it’s a bad, not-working-well example from MSDN.NOTE:
PasswordDeriveBytes.GetBytes()has been deprecated because of serious (security) issues within thePasswordDeriveBytesclass. The code above has been rewritten to use the saferRfc2898DeriveBytesclass instead (PBKDF2 instead of PBKDF1). Code generated with the above usingPasswordDeriveBytesmay be compromised.See also: Recommended # of iterations when using PKBDF2-SHA256?