首页 > 系统相关 >powershell保护明文密码

powershell保护明文密码

时间:2024-03-04 11:13:29浏览次数:33  
标签:SecureString 明文 密码 pwd key ConvertTo txt keyfile powershell

winrm脚本能运行了,就想着明文密码怎么也隐藏一下,网上搜了一圈,还是sparkdev的简单明了:

https://www.cnblogs.com/sparkdev/p/7258507.html

试着走一下,txt方式有效,高级的txt+key却报错“ConvertTo-SecureString : 输入数据不是完整的块”,一时也不知怎么解决,只得记下日后反刍。

$Password = 'pwd'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
ConvertFrom-SecureString $SecurePwd | Out-File "路径\pwd.txt"
$pass=get-content "路径\pwd.txt" | convertto-securestring

报错的txt+key步骤:

$pwd="路径\pwd.txt"
$keyfile="路径\pwd.key"
$key = new-object byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($key)
$key | out-file $keyfile
$key = Get-Content $keyfile
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,(Get-Content $pwd | ConvertTo-SecureString -Key $key)

标签:SecureString,明文,密码,pwd,key,ConvertTo,txt,keyfile,powershell
From: https://www.cnblogs.com/qiuwenzheng/p/18051404

相关文章