Encrypting/Decrypting XML Documents with Asymmetric Keys

  • Thread starter Thread starter dfa_geko
  • Start date Start date
D

dfa_geko

Hi All,

I had a question about encrypting and decrypting XML files using asymmetric
keys. I copied some sample code from MSDN, here are the samples:

http://msdn2.microsoft.com/en-us/library/ms229746.aspx
http://msdn2.microsoft.com/en-us/library/ms229919.aspx

The samples I used are the ones near the bottom of the page. (With a slight
modification of moving edElement.KeyInfo.AddClause(new KeyInfoEncryptedKey
(ek)); to before edElement.CipherData.CipherValue = encryptedElement;
statement in the Encryption sample)

However, I have found that when I encrypt a file using those techniques and
passing the XML file to another machine, I can't decrypt it. I get a Bad
Data exception. However, when I encrypt/decrypt with the same user/login,
it works fine! I thought it was the machine at first but it turns out it
wasn't because my ASPNET user wasn't able to decrypt the XML file that I
created from a console app of my user on the same machine. It doesn't work
on different machines. Does anyone know why??? I'm very confused. Or maybe
I'm doing something wrong. I'm wondering if anyone can shed any light on
this.

Much Thanks!!!
dfa_geko
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
The cspParameters set would need to be the same on both machines.
Peter

Hello Peter,

Thanks for the reply. If you check out the links, the csp parameters are
set the same. I pretty much just copy and pasted the sample code. The
problem persists...

Thanks,

dfa_geko
 
Ah! Found out why.. It looks like the RSA key is stored in the user
profile key store or the machine key store with this setting:
RSACryptoServiceProvider.UseMachineKeyStore

How come they key is not stored in the key container? Is the key
container not in the XML file? I guess not. I'm sorry for asking newbie
questions. I am a newbie at Encryption.

Thanks!

dfa_geko
 
Back
Top