Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt the password string in web.config

How can I encrypt the password string in web.config?

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" userName="[email protected]" password="test" port="587" />
      </smtp>
    </mailSettings>
</system.net>

What is the correct way to do it?

like image 421
Pedre Avatar asked Mar 30 '26 19:03

Pedre


2 Answers

You are best off encrypting that whole section of the file, as there is tooling built in for this, and it is automatically decrypted when the config file is read (so there's no need to change your code). This is described fully on MSDN, and uses the aspnet_regiis.exe tool.

like image 160
David M Avatar answered Apr 01 '26 10:04

David M


Check this Scott gu blog : Encrypting Web.Config Values in ASP.NET 2.0

Encrypting Custom Configuration Sections

<configSections>
   <section 
      name="sampleSection" 
      type="System.Configuration.SingleTagSectionHandler" 
   />
</configSections>

<MySecrets
   FavoriteMusic="Disco" 
   FavoriteLanguage="COBOL" 
   DreamJob="Dancing in the opening ceremonies of the Olympics" 
/>

Encrypt MySecrets

aspnet_regiis -pef MySecrets 
like image 40
Pranay Rana Avatar answered Apr 01 '26 10:04

Pranay Rana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!