Topic "Reading Password from File as Secure String"

Author Message
tkennedy
[View user's profile]

Joined: 2012-10-26
Posts: 11
I am doing some testing for some processes at work and I really like the possibility of using the .NET assembly. The issue I'm having is with the password. Our scripts are automated and the password is stored encrypted in a file. When I read the file the password is decrypted and converted to a SecureString. When I use the secure string I get an error:
Quote:
Connection has been unexpectedly closed. Server sent command exit status 0.

but if I typed my password in the password variable, the script works fine. I'm using Powershell, is there any way to read a SecureString from disk and use it with the .NET assembly?

Here are examples of my session options:

Code:
# Setup session options
$SessionOptions = New-Object WinSCP.SessionOptions
$SessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$SessionOptions.HostName = $FTPHost
$SessionOptions.UserName = $FTPUser
$SessionOptions.Password = Read-EncString $ENCFILE
#$SessionOptions.Password = "[thepasswordintext]" # This line works
$SessionOptions.SshHostKey = $SshHostKey


Thanksfor the help.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Sorry, no idea what Read-EncString does. Google does not give any results.
_________________
Martin Prikryl
tkennedy
[View user's profile]

Joined: 2012-10-26
Posts: 11
prikryl wrote:
Sorry, no idea what Read-EncString does. Google does not give any results.


Wow, my mistake. That's what I get for asking questions late on Friday.

The correct command is ConvertTo-SecureString. "The ConvertTo-SecureString cmdlet converts encrypted standard strings into secure strings." My problem may be that I simply don't know how to use the secure string so please forgive me if I am asking this in the wrong place.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
SessionOptions.Password is s string property, so cannot set it's value using some secure string object.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License