473,396 Members | 1,789 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.

Decryption with multiple keys gives error: "Unable to retrieve the decryption key."

3
I want to Encrypt and Decrypt different elements of xml file with different RSACryptoServiceProvider keys
Expand|Select|Wrap|Line Numbers
  1. RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams); 
  2. string publicKey = rsaKey.ToXmlString(false);
  3. RSACryptoServiceProvider rsaKey2 = new RSACryptoServiceProvider(cspParams2);
  4. string publicKey2 = rsaKey2.ToXmlString(false);
Here is my data file I want to encrypt:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <root>
  3. <creditcard>
  4. <number>19834209</number>
  5. <expiry>02/02/1890</expiry>
  6. </creditcard>
  7. <name>
  8. <first>abc</first>
  9. <mi>v</mi>
  10. <last>xyz</last>
  11. </name>
  12. <personal>
  13. <dob>01011790</dob>
  14. <gender>female</gender>
  15. </personal>
  16. </root>
  17.  
I encrypt <creditcard> element with publicKey and I encrypt <personal> element with
publicKey2 successfully.

However the problem comes in Decrypt
Expand|Select|Wrap|Line Numbers
  1. public static void Decrypt(XmlDocument Doc, RSA Alg, string KeyName)      
  2. {       
  3.  EncryptedXml exml = new EncryptedXml(Doc);        
  4.  exml.AddKeyNameMapping(KeyName, Alg);        
  5.  exml.DecryptDocument();      
  6. }
  7.  
I call the above code like this:
Expand|Select|Wrap|Line Numbers
  1. Decrypt(xmlDoc, rsaKey, publicKey);
  2. Decrypt(xmlDoc, rsaKey, publicKey2);
  3.  
I get Exception: "Unable to retrieve the decryption key."

However if I Encrypt both elements with same publicKey then Decrypt works.

This means If I encrypt elements of a document with single key Decrypt works. However If I encrypt elements of a document with multiple keys Decrypt fails. I can see why - because the Decrypt is working on the whole document. I want to be able to Decrypt each data element seperately with corresponding Encrypted key. MSDN article says it is possible. But I cannot locate examples.

Can someone please help?
Aug 30 '10 #1
0 1401

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
3
by: Amarpal | last post by:
Hi there, I wonder if someone can help me on VB/ASP.Net project. The project was developed by another developer on another machine. I need to load it and make some changes to this project. I get...
1
by: Shawn Wildermuth | last post by:
I have some simple code that loads a control with LoadControl and casts it to the codebehind object: Control ctrl = LoadControl("~/Controls/BlogEntryViewer.ascx"); BlogEntryViewer entry =...
5
by: meenasamy | last post by:
Hi all i have used a script that i downloaded and uses the fopen($url,'r'); function to access a url to retrieve data and i get this error Fatal error: fopen(): Unable to find the wrapper...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
4
by: Kuldeep | last post by:
Hi All, ..NET Framework - 1.0 ASP.NET Everytime I open my open, I get this error message "Unable to load one or more breakpoints" Even after this, I can build my application and run Please...
5
by: vshalpatel | last post by:
Hi I want to use SQL*Loader , an Oracle-supplied utility to load data from a flat file into one database tables. for this I have write the scripts in the SQL*LOADER control file named ...
2
by: mythilikumar | last post by:
Iam unable to complie my c programs? it shows out an error as "unable to include stdio.h" what to do,i feel that there is some problem in my computer what is the rectification?
0
by: Monty | last post by:
I have an installation package for my web application which has worked well. After rebuilding the package and running install, I began receiving this error message: Error 1001. Unable to get...
3
by: tvnaidu | last post by:
I need to bringup xterm of remote machine on local machine, I did login to remote and set "export DISPLAY=ip_local:0.0", then I issued "xhost +" command, so that I would like to launch GUI window of...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.