【问题标题】:What does this usage of ConvertTo-SecureString achieve?ConvertTo-SecureString 的这种用法实现了什么?
【发布时间】:2014-12-29 14:52:55
【问题描述】:

这个power shell命令的内部作用是什么

ConvertTo-SecureString "password" -AsPlainText -Force | ConvertFrom-SecureString;

【问题讨论】:

  • 文档中的哪些内容不清楚? technet.microsoft.com/en-us/library/hh849818.aspx
  • 我正在 linux 中编写代码,由于使用 poweshell 代码登录到 0365,我试图避免它并在 java 中做同样的事情,所以问了这个问题。
  • 您必须查看有关 O365 的 java 登录方法的文档。 powershell 凭据使用安全字符串。

标签: powershell


【解决方案1】:

按顺序操作:

  1. 获取文本password 并将其转换为内存中加密的字节字符串
  2. 将 SecureString 序列化为可保存到磁盘的加密字符串

SecureString 是字符串的内存加密表示,一旦不再使用,就会从内存中销毁。

基本上,这是一种加密字符串的方法,然后可以将其存储在磁盘上,而无需了解所需的所有各种加密实用程序。

【讨论】:

  • josh 感谢您的回复,什么可能是 power shell 中的字节编码。我想避免使用 power shell 并在 java 中执行相同的操作。你能帮我了解这些细节吗?
【解决方案2】:

阅读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.

【讨论】:

  • 感谢您的回复,power shell 中的字节编码可能是什么。我想避免使用 power shell 并在 java 中执行相同的操作。你能帮我了解这些细节吗?
  • 我不知道,但看看this link是否可以提供帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 2013-08-27
  • 2021-12-15
  • 1970-01-01
  • 2019-07-13
  • 2013-12-17
  • 1970-01-01
相关资源
最近更新 更多