I am trying to decrypt connection string in my app.config using customized Config Protection Provider named "MyConfigProtectionProvider". I don't have code for this Customized Config Provider as it is developed a long back, I have only DLL file. We changed our DB Username and Password. I want to decrypt my connection string in Web.Config
using this customized Config Protection Provider and change password to new password and encrypt it again
I have only app.config. So I renamed it to " web.config
". Then I added CODE I as shown below in my web.config
. I store key in my c drive and I need to give Key file path. " MyConfigProtectionProvider
" will encrypt it using this key.
We already have encrypted connection string as shown in CODE II . So I tried decrypting it using following command in cmd as Admin
aspnet_regiis.exe -pdf "connectionStrings" "C:\\Users\\Tejas\\Documents\\Email_Notification\\LatestBatchJobStatus\\BatchJobStatus\\Batch_Job_Status"
-prov "MyConfigProtectionProvider"
CODE I:
<configProtectedData defaultProvider="MyProtectionConfigurationProvider">
<providers><add name="MyProtectionConfigurationProvider" type="MyProtectionConfigurationProvider,
MyProtectionConfigurationProvider, Version=1.0.0.0,Culture=neutral,
PublicKeyToken=#############, processorArchitecture=MSIL"keyFilePath="C:\Users\Tejas\Documents\Email_Notification\LatestBatchJobStatus\BatchJobStatus\Batch_Job_Status\ConnectionKey\ConnectionKey.txt" /></providers></configProtectedData>
CODE II:
<connectionStrings configProtectionProvider="MyProtectionConfigurationProvider"> <EncryptedData>7Zqa4I623WR..................</EncryptedData></connectionStrings>
I am getting following error "An error has occurred: 0X80070002 The System cannot find the file specified".
What is the mistake I made?
It sounds like it can't find the configuration file. when decrypting, see if you can catch that FileNotFound exception to see more details about it:
private static string GetSecureConnectionString(string connStringName)
{
try
{
Log.Debug("Starting Decryption of ConnectionString Named " + connStringName);
var sEncrypted = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
Log.Debug("sEncrypted = " + sEncrypted);
_connectString = Encryption.Decrypt(sEncrypted);
Log.Debug("Did It Work? = " + _connectString);
return _connectString;
}
catch (System.IO.FileNotFoundException ex)
{
Log.Debug("ERROR - Unable to locate the configuration file [" + ex.FileName.ToString() + "]");
throw;
}
catch (ConfigurationErrorsException ex)
{
Log.Debug("ERROR - Error retrieving ConnectionString", ex);
throw;
}
catch (Exception ex)
{
Log.Debug("ERROR - Error Decrypting ConnectionString", ex);
throw new ApplicationException("ERROR: DataAccess:GetSecureConnectionString Failed. See ErrorLog for details.");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.