Powershell 明文密码安全使用

网友投稿 977 2022-09-16

Powershell 明文密码安全使用

Powershell 明文密码安全使用

在企业当中根据安全要求,明文密码是不允许保存在服务器文件当中的, 所以为了安全使用密码做了以下操作:

将明文密码转换为安全字符串 ​​ConvertTo-SecureString​​

$securepwd = ConvertTo-SecureString '123456' -AsPlainText -Force

创建一个随机的秘钥文件

$key = New-Object Byte[] 32[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($key)

使用秘钥加密安全字符串并保存到文件

$EncryPWD = ConvertFrom-SecureString $securepwd -Key $key |out-file d:\pwd.txt -force

使用​​ConvertTo-SecureString​​转换为安全字符串

4.1使用上一步刚刚生成的key文件加密 密码

$uname = 'testuser'$keyFile = d:\pwd.key$key = Get-Content $keyFile$pwdfile = d:\pwd.txt$user_pwd = Get-Content $pwdfile | ConvertTo-SecureString -Key $key$user_cred = New-Object System.Management.Automation.PSCredential($uname, $user_pwd)

4.2如果已有key文件, 读取key 文件内容后再使用key 文件加密 密码

[byte[]]$key = gc d:\pwd.keyConvertFrom-SecureString $securepwd -Key $key | Out-file "D:\user_pwd.txt" -Force$pwdfile = "D:\user_pwd.txt"$user_pwd = Get-Content $pwdfile | ConvertTo-SecureString -Key $key$user_cred = New-Object System.Management.Automation.PSCredential($uname, $user_pwd)

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:移动硬盘数据恢复之WD4T二次开盘固件190模块修复成功
下一篇:Python之Selenium如何正确运用?案例详解(selenium python实例)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~