How can I encrypt the password string in web.config?
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" userName="guess@gmail.com" password="test" port="587" />
</smtp>
</mailSettings>
</system.net>
What is the correct way to do it?
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.exetool.