public override void Run()
        {
            var provider = new RsaProtectedConfigurationProvider();

            provider.Initialize("RSA-key from key container", new NameValueCollection()
            {
                {"keyContainerName", _containerName},
                {"useMachineContainer", "true"}
            });

            XmlDocument doc = new XmlDocument();
            doc.Load(_configFile);

            var el = doc.DocumentElement[_sectionName];
            if(el == null)
                throw new ApplicationException("section not found");

            var cryptEl = doc.CreateElement(_sectionName);
            var prNameAttr = doc.CreateAttribute("configProtectionProvider");
            prNameAttr.Value = _providerName;
            cryptEl.Attributes.Append(prNameAttr);

            var cryptData = provider.Encrypt(el);
            cryptData = doc.ImportNode(cryptData, true);
            cryptEl.AppendChild(cryptData);
            doc.DocumentElement.ReplaceChild(cryptEl, el);

            doc.Save(_configFile);
        }
Exemple #2
0
        public override void Run()
        {
            var provider = new RsaProtectedConfigurationProvider();

            provider.Initialize("RSA-key from key container", new NameValueCollection()
            {
                {"keyContainerName", _containerName},
                {"useMachineContainer", "true"}
            });

            XmlDocument doc = new XmlDocument();
            doc.Load(_configFile);

            var el = doc.DocumentElement[_sectionName];
            if (el == null)
                throw new ApplicationException("section not found");

            var cryptData = el["EncryptedData", "http://www.w3.org/2001/04/xmlenc#"];
            if (cryptData == null)
                throw new ApplicationException("crypt data not found");

            var decryptedData = provider.Decrypt(cryptData);
            decryptedData = doc.ImportNode(decryptedData, true);
            doc.DocumentElement.ReplaceChild(decryptedData, el);

            doc.Save(_configFile);
        }
 private RsaProtectedConfigurationProvider CreateRSAProvider(string containerName, string csp, long options)
 {
     RsaProtectedConfigurationProvider provider = new RsaProtectedConfigurationProvider();
     NameValueCollection config = new NameValueCollection();
     config.Add("keyContainerName", containerName);
     config.Add("cspProviderName", csp);
     config.Add("useMachineContainer", ((options & 0x100000000000L) != 0L) ? "false" : "true");
     provider.Initialize("foo", config);
     return provider;
 }
 private RsaProtectedConfigurationProvider CreateRSAProvider(string containerName, string csp, long options)
 {
     RsaProtectedConfigurationProvider prov = new RsaProtectedConfigurationProvider();
     NameValueCollection nvc = new NameValueCollection();
     nvc.Add("keyContainerName", containerName);
     nvc.Add("cspProviderName", csp);
     nvc.Add("useMachineContainer", ((options & DO_RSA_PKU) != 0) ? "false" : "true");
     prov.Initialize("foo", nvc);
     return prov;
 }