Expand|Select|Wrap|Line Numbers
- RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);
- string publicKey = rsaKey.ToXmlString(false);
- RSACryptoServiceProvider rsaKey2 = new RSACryptoServiceProvider(cspParams2);
- string publicKey2 = rsaKey2.ToXmlString(false);
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8" ?>
- <root>
- <creditcard>
- <number>19834209</number>
- <expiry>02/02/1890</expiry>
- </creditcard>
- <name>
- <first>abc</first>
- <mi>v</mi>
- <last>xyz</last>
- </name>
- <personal>
- <dob>01011790</dob>
- <gender>female</gender>
- </personal>
- </root>
publicKey2 successfully.
However the problem comes in Decrypt
Expand|Select|Wrap|Line Numbers
- public static void Decrypt(XmlDocument Doc, RSA Alg, string KeyName)
- {
- EncryptedXml exml = new EncryptedXml(Doc);
- exml.AddKeyNameMapping(KeyName, Alg);
- exml.DecryptDocument();
- }
Expand|Select|Wrap|Line Numbers
- Decrypt(xmlDoc, rsaKey, publicKey);
- Decrypt(xmlDoc, rsaKey, publicKey2);
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?