473,666 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
I want to Encrypt and Decrypt different elements of xml file with different RSACryptoServic eProvider 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 1443

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

Similar topics

0
7379
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 channal hosting into IIS. There is a class B which is also available through remoting hosted on IIS on the same URI. B creates new of A inside a function. It succeed and able to create instance of A inside B first time. But it failes in 2nd attempt when...
3
8579
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 error message "Unable to read project file (name of the file). The Project file has been renamed or is no longer in the solution. I can't progress any further, unless I can load the project. Please help!!!
1
2185
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 = (BlogEntryViewer)ctrl; About 80% of the time this fails in the cast. The BlogEntryViewer.ascx file specifies the right file (and it compiles btw): <%@ Control Language="C#" AutoEventWireup="true" CodeFile="BlogEntryViewer.ascx.cs"
5
43204
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 "https" - did you forget to enable it when you configured PHP? i checked the 'allow_url_fopen = On' in php.ini and it is set to On, and still it didn't work
9
3775
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 code. for example, this is bad practice: header.h #include <string> using std::string;
4
5556
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 Help!
5
36068
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 loader.ctl. actual data file is mydata.csv that I have mentioned under ‘load data’ section in loader.ctl . P.N : I am using my personal oracle installed on windows Pc. not using any n/w resources to access oracle DB Now I know we need to invoke...
2
7587
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
3483
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 installer types in the <MY_APPLICATION>.dll assembly. --Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. The install package has a Custom Action, but it has always worked fine before. If...
3
2131
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 remote machine locally, I get this error (first I did login to remote and issued these). # export DISPLAY=ip_local:0.0 # xhost + xhost: unable to open display "ip_local:0.0" any idea?.
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.