By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,901 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,901 IT Pros & Developers. It's quick & easy.

Encrypting/Decrypting XML Documents with Asymmetric Keys

P: n/a
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
Apr 6 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The cspParameters set would need to be the same on both machines.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"dfa_geko" wrote:
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
Apr 6 '07 #2

P: n/a
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
<pb*******@yahoo.yabbadabbadoo.comwrote in news:CE55F5D0-5046-41CD-B4F9-
CF**********@microsoft.com:
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
Apr 6 '07 #3

P: n/a
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

"dfa_geko" <no****@nospam.comwrote in
news:Xn*****************************@69.28.173.184 :
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
Apr 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.