// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
using System.Xml;
+using System.IO;
using System.Collections.Specialized;
using System.Security.Cryptography;
+using System.Security.Cryptography.Xml;
namespace System.Configuration
{
public sealed class RsaProtectedConfigurationProvider: ProtectedConfigurationProvider
{
+ string cspProviderName;
string keyContainerName;
bool useMachineContainer;
+ bool useOAEP;
+
+ RSACryptoServiceProvider rsa;
+
+ RSACryptoServiceProvider GetProvider ()
+ {
+ if (rsa == null) {
+ CspParameters c = new CspParameters ();
+ c.ProviderName = cspProviderName;
+ c.KeyContainerName = keyContainerName;
+ if (useMachineContainer)
+ c.Flags |= CspProviderFlags.UseMachineKeyStore;
+
+ rsa = new RSACryptoServiceProvider (c);
+ }
+
+ return rsa;
+ }
public RsaProtectedConfigurationProvider ()
{
[MonoTODO]
public override XmlNode Decrypt (XmlNode encrypted_node)
{
- throw new NotImplementedException ();
+ XmlDocument doc = new ConfigurationXmlDocument ();
+
+ doc.Load (new StringReader (encrypted_node.OuterXml));
+
+ EncryptedXml ex = new EncryptedXml (doc);
+
+ ex.AddKeyNameMapping ("Rsa Key", GetProvider ());
+
+ ex.DecryptDocument ();
+
+ return doc.DocumentElement;
}
[MonoTODO]
public override XmlNode Encrypt (XmlNode node)
{
- throw new NotImplementedException ();
+ XmlDocument doc = new ConfigurationXmlDocument ();
+
+ doc.Load (new StringReader (node.OuterXml));
+
+ EncryptedXml ex = new EncryptedXml (doc);
+
+ ex.AddKeyNameMapping ("Rsa Key", GetProvider ());
+
+ EncryptedData d = ex.Encrypt (doc.DocumentElement, "Rsa Key");
+
+ return d.GetXml();
}
[MonoTODO]
base.Initialize (name, configurationValues);
keyContainerName = configurationValues ["keyContainerName"];
+ cspProviderName = configurationValues ["cspProviderName"];
flag = configurationValues ["useMachineContainer"];
if (flag != null && flag.ToLower() == "true")
useMachineContainer = true;
+
+ flag = configurationValues ["useOAEP"];
+ if (flag != null && flag.ToLower() == "true")
+ useOAEP = true;
}
[MonoTODO]
[MonoTODO]
public void ExportKey (string xmlFileName, bool includePrivateParameters)
{
- throw new NotImplementedException ();
+ RSACryptoServiceProvider prov = GetProvider ();
+ string xml = prov.ToXmlString (includePrivateParameters);
+
+ FileStream stream = new FileStream (xmlFileName, FileMode.OpenOrCreate, FileAccess.Write);
+ StreamWriter writer = new StreamWriter (stream);
+
+ writer.Write (xml);
+ writer.Close ();
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public string CspProviderName
{
- get { throw new NotImplementedException (); }
+ get { return cspProviderName; }
}
public string KeyContainerName {
get { return keyContainerName; }
}
- [MonoTODO]
public RSAParameters RsaPublicKey {
- get { throw new NotImplementedException (); }
+ get {
+ RSACryptoServiceProvider prov = GetProvider ();
+ return prov.ExportParameters (false);
+ }
}
public bool UseMachineContainer {
get { return useMachineContainer; }
}
- [MonoTODO]
public bool UseOAEP {
- get { throw new NotImplementedException (); }
+ get { return useOAEP; }
}
}
}
-#endif
+