PowerShell: 隐藏明文密码
2015-10-13 15:58
483 查看
本文描述如何加密 PowerShell 中的敏感信息,从而避免敏感信息(诸如密码)在代码中被显式的展现出来。这里我们使用 ConvertFrom-SecureString 命令来完成加密操作,需要注意的是,如果我们没有指定Key,那么,将采用基于 Windows 内置的 DPAPI 进行数据的加密。这种情况下,原文的加密和解密必须在同一台机器上,且基于同一个User去进行。
ConvertFrom-SecureString [-SecureString] <SecureString> [[-SecureKey] <SecureString> ] [ <CommonParameters>]
你可以从这里了解该命令的更多信息。
* If no key is specified, the Windows Data Protection API (DPAPI) is used to encrypt the standard string representation.
Your secret was automatically encrypted by the built-in Windows data protection API (DPAPI), using your identity and your machine as encryption key. So only you (or any process that runs on your behalf) can decipher the secret again, and only on the machine where it was encrypted.
加密方式:
[ps]
write-host "Please enter your plain text. (Run this script as Administrator)"
$plainText = Read-Host | ConvertTo-SecureString -AsPlainText -force
$encryptedText = $plainText | ConvertFrom-SecureString
write-host $encryptedText
[/ps]
解密方式:
[ps]
$password = $encryptedText | ConvertTo-SecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential("JustGiveAName", $password)
$cred.GetNetworkCredential().Password
[/ps]
查看原文:http://nap7.com/me/powershell-hide-plain-password/
ConvertFrom-SecureString [-SecureString] <SecureString> [[-SecureKey] <SecureString> ] [ <CommonParameters>]
你可以从这里了解该命令的更多信息。
* If no key is specified, the Windows Data Protection API (DPAPI) is used to encrypt the standard string representation.
Your secret was automatically encrypted by the built-in Windows data protection API (DPAPI), using your identity and your machine as encryption key. So only you (or any process that runs on your behalf) can decipher the secret again, and only on the machine where it was encrypted.
加密方式:
[ps]
write-host "Please enter your plain text. (Run this script as Administrator)"
$plainText = Read-Host | ConvertTo-SecureString -AsPlainText -force
$encryptedText = $plainText | ConvertFrom-SecureString
write-host $encryptedText
[/ps]
解密方式:
[ps]
$password = $encryptedText | ConvertTo-SecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential("JustGiveAName", $password)
$cred.GetNetworkCredential().Password
[/ps]
查看原文:http://nap7.com/me/powershell-hide-plain-password/
相关文章推荐
- Windows下运行adb
- 由12306.cn谈谈网站性能技术(转自 酷壳 – CoolShell.cn 原作者陈皓)
- -bash: /bin/rm: Argument list too long
- X-shell、putty秘钥登录方式整理、普通用户密钥登录
- Shell编程实现Kill线程
- shell脚本中获取日期
- shell 删除空行
- 写出健壮的Bash脚本
- shell命令之文件压缩与解压(常用)
- 【powershell】查看powershell脚本版本号
- 基于sparksql调用shell脚本执行SQL
- hbase常用shell命令
- 【干货】JMeter BeanShell 应用
- 【干货】JMeter BeanShell 应用
- 【干货】JMeter BeanShell 应用
- shell脚本截取日期处理
- Shell编程——变量、判断、重复动作
- linux shell 编程1文件权限检测、字符串比较判断、数值大小比较、时间获取以及单引号双引号反引号等的使用
- Shell基础-环境变量配置文件
- -bash: ssh: command not found的解决办法