PDA

View Full Version : مشکل در حفاظت از app.config



mir555
دوشنبه 30 آبان 1390, 15:04 عصر
با سلام و خسته نباشید
دوستان من app.config برنامه خودم را با استفاده از تابع زیر encrypt کردم و روی کامپیوتر خودم به درستی عمل می کند و لی زمانی که برنامه روی سیستم دیگری کپی می شود پیام خطا می دهد که نمی توان dycrypt انجام دهد لطفا راهنمایی کنید

static void ToggleConfigEncryption(string exeConfigName)
{
// Takes the executable file name without the
// .config extension.
try
{
// Open the configuration file and retrieve
// the connectionStrings section.
Configuration config = ConfigurationManager.OpenExeConfiguration(exeConfi gName);


ConnectionStringsSection section =
config.GetSection("connectionStrings")
as ConnectionStringsSection;

if (section.SectionInformation.IsProtected)
{
// Remove encryption.
// section.SectionInformation.UnprotectSection();
}
else
{
// Encrypt the section.
section.SectionInformation.ProtectSection(
"DataProtectionConfigurationProvider");
}
// Save the current configuration.
AppSettingsSection st2 = config.GetSection("appSettings") as AppSettingsSection;
if (!st2.SectionInformation.IsProtected)
st2.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");

// config.Sections.Add(
config.Save(ConfigurationSaveMode.Full);

// Console.WriteLine("Protected={0}",
// section.SectionInformation.IsProtected);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

تو کامپیوتر دیگری که اجرا می کنم پیام زیر نشون داده میشه
78192

Sp|R|T
دوشنبه 30 آبان 1390, 18:31 عصر
سلام

چند وقت پیش همین مشکل رو داشتم که به این نتیجه و جواب رسیدم:


How are you encrypting the data on the Windows XP machine? Did you copy the config file from your Windows 7 machine by any chance?
The Encryption API uses a unique encryption key for your account/machine to encrypt the data. That means that a config file encrypted on one machine cannot be decrypted on another.
So you will have to encrypt the config file on the XP machine, or use a custom encryption key which you then have to install onto the machine in order for you to read the connection string.


و


"Key" is involved Encryption/Decryption always. If you just enrypt a file on your PC and share the file to anyone they can't decrypt the data without the key. So you have to share the key along with the file. Atleast you have to hard code the key in your source code or keep it resources.

مختصر:

app.config فقط روی همون کامپیوتری که اِنکریپت شده میتونه dycrypt بشه ! در واقع کلید این قفل فقط توی همون کامپیوتر خودتون وجود داره که قفل رو باز کنه و در کامپیوتر های دیگه معنی نداره !

یا هم اینکه یه کلید واسش بسازین و روی کامپیوتر های دیگه نصب کنید؛ که این کار عملآ انگار app.config رو انکریپت نکردین !