【问题标题】:Making a securestring XML file制作安全字符串 XML 文件
【发布时间】:2019-06-20 21:20:24
【问题描述】:

我怎样才能生成一个看起来像这样的文件

<Configuration>
  <UserName>oracle</UserName>
  <Password>01000000d08c9ddf...</Password>
  <SshFingerPrint>01000000d08c9ddf0115d...</SshFingerPrint>
</Configuration>

我想在我的脚本中使用 XML 文件

[xml]$config = Get-Content "$PSScriptRoot\config.xml"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Scp
    HostName = "127.0.0.1"
    UserName = $config.Configuration.UserName
    Password = ConvertTo-SecureString $config.Configuration.Password
    SshHostKeyFingerprint = ConvertTo-SecureString $config.Configuration.SshFingerPrint
}

$session = New-Object WinSCP.Session

【问题讨论】:

  • 补充 Martin Prikryl 给你的东西。在 PowerShell 脚本中处理安全凭证是一个经常被谈论和充分覆盖/记录的事情。无论是使用 xml、txt、注册表、数据库还是 Windows 凭据管理器。没有什么能阻止您使用它们来创建您所追求的文件。在此处查看示例源列表:--- reddit.com/r/PowerShell/comments/bv7ywa/… --- 因此,有许多用例可供选择。

标签: xml powershell winscp securestring


【解决方案1】:

嗯,您从WinSCP article Protecting credentials used for automation 获取了该代码。

还有那篇文章shows how to encrypt the password在配置文件中使用:

要加密密码,请使用ConvertFrom-SecureString cmdlet:

Read-Host -AsSecureString | ConvertFrom-SecureString

要加密公钥,您可以使用相同的技术。但这没有任何意义。这是公共键。无需加密。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 2016-11-02
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    相关资源
    最近更新 更多