zoukankan      html  css  js  c++  java
  • 脚本中使用密文密码

    将明文转换为密文

    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
  • 相关阅读:
    CD4051
    sbit和sfr的定义
    EEPROM与FLASH的区别
    九LWIP学习笔记之最后的战役
    八LWIP学习笔记之用户编程接口(NETCONN)
    七LWIP学习笔记之传输控制协议(TCP)
    六LWIP学习笔记之用户数据报协议(UDP)
    java实现二叉查找树
    线程的锁对象
    MAP
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/3989899.html
Copyright © 2011-2022 走看看