Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Reading Password from File as Secure String

SessionOptions.Password is s string property, so cannot set it's value using some secure string object.
tkennedy

Re: Reading Password from File as Secure String

martin 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

Re: Reading Password from File as Secure String

Sorry, no idea what Read-EncString does. Google does not give any results.
tkennedy

Reading Password from File as Secure String

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:
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:

# 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.