Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My connection String is,

<connectionString value="Data Source=HEMTECH\SA;Initial Catalog=HemWizard;User ID=sa; Password=hemtech;" />


My Encrypted connection string is ( i want below output for above connection string )

<add key="DBConnString" value="RGF0YSBTb3VyY2U9SEVNVEVDSFxTQTtJbml0aWFsIENhdGFsb2c9SGVtV2l6YXJkO1VzZXIgSUQ9c2E7IFBhc3N3b3JkPWhlbXRlY2g7"/>


I can't do like above encrypted connection string so help me how to encrypt my connection string.

What I have tried:

public static void EncryptConnectionString(bool encrypt, string fileName)
{
Configuration configuration = null;
try
{
// Open the configuration file and retrieve the connectionStrings section.
configuration = ConfigurationManager.OpenExeConfiguration(fileName);
ConnectionStringsSection configSection = configuration.GetSection("connectionStrings") as ConnectionStringsSection;
if ((!(configSection.ElementInformation.IsLocked)) && (!(configSection.SectionInformation.IsLocked)))
{
if (encrypt && !configSection.SectionInformation.IsProtected)
{
//this line will encrypt the file
configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}

if (!encrypt && configSection.SectionInformation.IsProtected)//encrypt is true so encrypt
{
//this line will decrypt the file. 
configSection.SectionInformation.UnprotectSection();
}
//re-save the configuration file section
configSection.SectionInformation.ForceSave = true;
// Save the current configuration

configuration.Save();
Process.Start("notepad.exe", configuration.FilePath);
//configFile.FilePath 
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Posted
Updated 14-Nov-17 22:42pm

1 solution

It's not encrypted. It's base64 encoded. Try any online base64 decoder, such as Base64 Decode and Encode - Online[^]
 
Share this answer
 
Comments
Akshada Sane 15-Nov-17 7:37am    
Thank you so much dear... it's very helpful for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900