473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Encrypting/Decrypting XML Documents with Asymmetric Keys

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
3 2865
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
=?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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Piotr | last post by:
MS has published on its sites javascript encoder, which enables "encrypting" javascript code. It allows hiding js code from being seen as a text file. There is a decoder for it, available in the...
9
by: Brian P. Hammer | last post by:
All - I have an app that saves data to a xml file via a dataset. Our company stores some data in various xml files that is now considered a risk under its security policy. What's the best way to...
13
by: Andy Chau | last post by:
I try to use RSA to implement the following scheme but wasn't sucessful. Sever encrypt a message using a public key, the client decrpyt the message using a private key. I don't want the client...
1
by: Bart | last post by:
Dear all, I would like to encrypt a large amount of data by using public/private keys, but I read on MSDN: "Symmetric encryption is performed on streams and is therefore useful to encrypt large...
0
by: cmrchs | last post by:
Hi, Using the RSA-crypto algorithm in .NET , when actually encrypting/decrypting, all the code samples I ran into always used something like, to encrypt : // create keypair and store in...
0
by: cmrchs | last post by:
Hi, Using the RSA-crypto algorithm in .NET , when actually encrypting/decrypting, all the code samples I ran into always used something like, to encrypt : ' create keypair and store in...
4
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the...
2
by: Amar | last post by:
Hi All, I want to insert my password into the mysql database by encrypting it so that I can also retrieve the password. Before I was using sha1() for encrypting password,but it is an one way...
2
by: SeeSharp Bint | last post by:
Visual Studio 2005, dotnet, c#. Microsoft SQL Server. Windows XP forms application. Temporarily, for my database application, I have been storing the various elements of database connection...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.