Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Alwyn
(70)
srinivas kante...
(67)
Abhisek Panda
(42)
Last 7 Days
Alwyn
(734)
nishithraj
(512)
Gaurav Arora
(503)
more...
Resources
»
Code Snippets
»
C# Syntax
»
Encrypt decrypt data within your configuration file
Posted Date: 16 Nov 2008
Resource Type:
Code Snippets
Category:
C# Syntax
Author:
MASNSN
Member Level:
Gold
Rating:
Points
: 10
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Configuration;
using System.Windows.Forms;
namespace EncryptConfigurationFile
{
class ConfigurationSectionEncryptor
{
private ConfigurationSectionEncryptor() { }
///
/// This static method helps encrypt the given data set
///
///
String : The configuration file path
public static void Encrypt(string ConfigurationFilePath)
{
//Create a new ExeConfigurationFileMap
ExeConfigurationFileMap oFile = new ExeConfigurationFileMap();
//Precise its path
oFile.ExeConfigFilename = ConfigurationFilePath;
//Create a new configuration object related to the configuration file
Configuration oConfiguration = ConfigurationManager.OpenMappedExeConfiguration(oFile, ConfigurationUserLevel.None);
//Create a section and set it as the targeted section
ConnectionStringsSection oSection = oConfiguration.GetSection("connectionStrings") as ConnectionStringsSection;
//if the section is already encrypted dont ecrypt it again
if (oSection != null && !oSection.SectionInformation.IsProtected)
{
//The section ecryption
oSection.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
//Update the configuration file
oConfiguration.Save();
MessageBox.Show("Connection string encrypted");
}
}
///
/// This static method helps encrypt the given data set
///
///
String : The configuration file path
public static void Decrypt(string ConfigurationPath)
{
//Create a new ExeConfigurationFileMap
ExeConfigurationFileMap oFile = new ExeConfigurationFileMap();
//Precise its path
oFile.ExeConfigFilename = Application.StartupPath + @"\EncryptConfigurationFile.exe.config";
//Create a new configuration object related to the configuration file
Configuration oConfiguration = ConfigurationManager.OpenMappedExeConfiguration(oFile, ConfigurationUserLevel.None);
//Create a section and set it as the targeted section
ConnectionStringsSection oSection = oConfiguration.GetSection("connectionStrings") as ConnectionStringsSection;
if (oSection != null && oSection.SectionInformation.IsProtected)
{
oSection.SectionInformation.UnprotectSection();
oConfiguration.Save();
MessageBox.Show("Connection string decrypted");
}
}
}
}
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
Encrypt data configuration file
.
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Connect to Excel as data source
Previous Resource:
Zip and Unzip files using C#
Return to Discussion Resource Index
Post New Resource
Category:
C# Syntax
Post resources and
earn money
!
More Resources
Get values from a database to datagrid
C# code for reading and writing XML file in simple way
using security.principle and environment namespace
Singleton design pattern for c# application
Storing and Retrieving Image in SQL Server
How does you get record number from 2 to 6 from a dataset of 10 records?
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use