首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ConvertTo-SecureString的这种用法实现了什么?

ConvertTo-SecureString的这种用法实现了什么?
EN

Stack Overflow用户
提问于 2014-12-29 22:52:55
回答 2查看 717关注 0票数 0

此power shell命令的内部操作是什么

代码语言:javascript
运行
复制
ConvertTo-SecureString "password" -AsPlainText -Force | ConvertFrom-SecureString;
EN

回答 2

Stack Overflow用户

发布于 2014-12-29 23:00:20

按顺序执行的操作:

获取文本并将其转换为内存中的加密字符串bytes

  • Serialize SecureString,再转换为可保存到disk的加密字符串

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

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

票数 2
EN

Stack Overflow用户

发布于 2014-12-29 23:02:04

读一下get-help convertto-securestring的第二个例子,你会找到答案的。基本上,您的命令将加密密码,并将显示为加密文本。

代码语言:javascript
运行
复制
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.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27691064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档