How does one securely handle passwords in a custom written PowerShell cmdlet?

后端 未结 5 777
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 16:43

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

[Cmdlet(VerbsData.Export, \"SampleData\")]
public class ExportSample         


        
5条回答
  •  忘掉有多难
    2021-01-22 17:28

    If you are writing a C# PowerShell Cmdlet and one of the parameters requires the user to enter a password it should be obfuscated.

    To do this you need to be using System.Security;

    And then your parameter type should be SecureString.

    So using your example:

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

提交回复
热议问题