Differences

This shows you the differences between the selected revisions of the page.

2014-08-27 2015-11-03
batch file syntax highlighting (martin) securepassword (martin)
Line 35: Line 35:
In [[library_powershell|PowerShell]] code using [[library|WinSCP .NET library]] you can use ''[[http://technet.microsoft.com/en-us/library/hh849787.aspx|Get-Content]]'' cmdlet to read an XML configuration file. In [[library_powershell|PowerShell]] code using [[library|WinSCP .NET library]] you can use ''[[http://technet.microsoft.com/en-us/library/hh849787.aspx|Get-Content]]'' cmdlet to read an XML configuration file.
-For example with following XML configuration file (''config.xml''):+For example with following %%XML%% configuration file (''config.xml''):
<code xml> <code xml>
Line 58: Line 58:
... ...
 +</code>
 +
 +You can also leverage Windows Data Protection API to encrypt the password in the %%XML%% file.
 +
 +To encrypt the password use ''[[https://technet.microsoft.com/en-us/library/hh849814.aspx|ConvertFrom-SecureString]]'' cmdlet:
 +
 +<code powershell>
 +Read-Host -AsSecureString | ConvertFrom-SecureString
 +</code>
 +
 +A password encrypted this way can be decrypted by the same Windows account only.
 +
 +Store the encrypted password to the %%XML%% file instead of the plain-text one:
 +
 +<code xml>
 +<Configuration>
 +  <UserName>martin</UserName>
 +  <Password>01000000d08c9ddf0115d1118c7a00c04fc297eb01000000cf6dbc52515...</Password>
 +</Configuration>
 +</code>
 +
 +To decrypt the password, use ''[[https://technet.microsoft.com/en-us/library/hh849818.aspx|ConvertTo-SecureString]]'' cmdlet and assign the resulting ''[[https://msdn.microsoft.com/en-us/library/system.security.securestring.aspx|SecureString]]'' to ''SessionOptions.SecurePassword'':
 +
 +<code powershell>
 +$sessionOptions.SecurePassword = ConvertTo-SecureString $config.Configuration.Password
</code> </code>

Last modified: by martin