码迷,mamicode.com
首页 > 其他好文 > 详细

脚本中使用密文密码

时间:2014-09-24 10:34:26      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   使用   ar   for   div   

将明文转换为密文

1 #将明文转换为密文
2 $storage = "d:\pass.txt"
3 $mysecret = ‘mypassword.‘
4 
5 $mysecret | 
6   ConvertTo-SecureString -AsPlainText -Force |
7   ConvertFrom-SecureString |
8   Out-File -FilePath $storage

 

#将密文转换回明文

1 #将密文转换回明文
2 $storage = "d:\pass.txt"
3 
4 $secureString = Get-Content -Path $storage | ConvertTo-SecureString
5 $ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($secureString)
6 $mysecret = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) 
7 $mysecret   

 

#将加密后的密码保存在PowerShell脚本中使用

 1 #此为加密后的密文密码
 2 $storage = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000142c3028558376439749dc9d50f6124a00000000020000000000106600000001000020000000bfb113b1fda4d92cc94eb770b2fda81956fa0d4ab633d7e736af63f7f5e270f6000000000e800000000200002000000048de85352a65d2deb01be43affdc25b54e598cce6f8d9f936fdfa4be16752b8720000000419c3990839f7028fc2056fd97a404f3e79ed3fe22770d66a0bc8a85f78f7994400000005780e2034bd644d68a9acfa2b385d71b24f68b0acd1358553add8b7c3b0ed597aff53bf78cc44ce60ee2e6228b154b4ca520d50c9133843397f12033c60b6f73"
 3 #对密文进行解密  
 4 $secureString = $storage | ConvertTo-SecureString
 5 $ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($secureString)
 6 $serverpass = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) 
 7 $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force
 8 $UserName = "administrator"      #定义管理员账户名称
 9 $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) 
10 
11 Enter-PSSession -ComputerName 10.10.12.12 -Credential $cred

 

脚本中使用密文密码

标签:style   blog   color   io   os   使用   ar   for   div   

原文地址:http://www.cnblogs.com/dreamer-fish/p/3989899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!