此power shell命令的内部操作是什么
ConvertTo-SecureString "password" -AsPlainText -Force | ConvertFrom-SecureString;
答案 0 :(得分:2)
按顺序执行的操作:
password
并将其转换为内存中加密的字节串SecureString是字符串的内存中加密表示,一旦不再使用,就会从内存中销毁。
基本上它是一种加密字符串的方式,然后可以存储在磁盘上,而不必了解所需的所有各种加密实用程序。
答案 1 :(得分:1)
阅读get-help convertto-securestring
的第二个例子,你会找到答案。基本上,您的命令将加密密码,并将显示为加密文本。
PS C:\> $secure = read-host -assecurestring
PS C:\>$secure
System.Security.SecureString
PS C:\>$encrypted = convertfrom-securestring -securestring $secure
PS C:\>$encrypted
01000000d08c9ddf0115d1118c7a00c04fc297eb010000001a114d45b8dd3f4aa11ad7c0abdae9800000000002000000000003660000a8000000100000005df63cea84bfb7d70bd6842e7
efa79820000000004800000a000000010000000f10cd0f4a99a8d5814d94e0687d7430b100000008bf11f1960158405b2779613e9352c6d14000000e6b7bf46a9d485ff211b9b2a2df3bd
6eb67aae41
PS C:\>$secure2 = convertto-securestring -string $encrypted
PS C:\>$secure2
System.Security.SecureString
This example shows how to create a secure string from user input, convert the secure string to an encrypted standard string, and then convert the encrypted standard string back
to a secure string.
The first command uses the AsSecureString parameter of the Read-Host cmdlet to create a secure string. After you enter the command, any characters that you type are converted
into a secure string and then saved in the $secure variable.
The second command displays the contents of the $secure variable. Because the $secure variable contains a secure string, Windows PowerShell displays only the
System.Security.SecureString type.
The third command uses the ConvertFrom-SecureString cmdlet to convert the secure string in the $secure variable into an encrypted standard string. It saves the result in the
$encrypted variable. The fourth command displays the encrypted string in the value of the $encrypted variable.
The fifth command uses the ConvertTo-SecureString cmdlet to convert the encrypted standard string in the $encrypted variable back into a secure string. It saves the result in
the $secure2 variable. The sixth command displays the value of the $secure2 variable. The SecureString type indicates that the command was successful.