如何安全地处理自定义编写的PowerShell cmdlet中的密码? [英] How does one securely handle passwords in a custom written PowerShell cmdlet?

查看:298
本文介绍了如何安全地处理自定义编写的PowerShell cmdlet中的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个自定义的PowerShell Cmdlet,它导出数据并使用密码加密它。

  [Cmdlet(VerbsData.Export ,SampleData)] 
public class ExportSampleData:PSCmdlet
{
[Parameter(Mandatory = true)]
public string Password
{
get;
set;
}

/ *其他参数* /
}

如何妥善处理密码?例如,当管理员在控制台中键入值时,我想禁止显示该值。其他选项包括读取包含加密密码的文件。



我知道PSCredential,但需要一个用户名,在这种情况下没有意义。

解决方案

如果您只想获取密码,可以使用



code> -asSecureString 参数中的code> Read-Host cmdlet。



此参数屏蔽输入。


Assume I have a custom PowerShell Cmdlet that exports data and encrypts it using a password.

[Cmdlet(VerbsData.Export, "SampleData")]
public class ExportSampleData : PSCmdlet
{
    [Parameter(Mandatory = true)]
    public string Password
    {
        get;
        set;
    }

    /* additional parameters */
}

How does one appropriately handle the passwords securely? For example, I'd like to prevent the value from being displayed when the administrator types it in the console. Other options include reading a file that contains an encrypted password.

I'm aware of PSCredential but that requires a user name which makes no sense in this scenario.

解决方案

If you only want to obtain the password, you can use

Read-Host cmdlet with the–asSecureString parameter.

This parameter mask the input.

这篇关于如何安全地处理自定义编写的PowerShell cmdlet中的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆