Unprotect-CmsMessage

使用加密消息语法格式解密已加密的内容。

语法

Unprotect-CmsMessage
         [-EventLogRecord] <EventLogRecord>
         [[-To] <CmsMessageRecipient[]>]
         [-IncludeContext]
         [<CommonParameters>]
Unprotect-CmsMessage
         [-Content] <string>
         [[-To] <CmsMessageRecipient[]>]
         [-IncludeContext]
         [<CommonParameters>]
Unprotect-CmsMessage
         [-Path] <string>
         [[-To] <CmsMessageRecipient[]>]
         [-IncludeContext]
         [<CommonParameters>]
Unprotect-CmsMessage
         [-LiteralPath] <string>
         [[-To] <CmsMessageRecipient[]>]
         [-IncludeContext]
         [<CommonParameters>]

说明

Unprotect-CmsMessage cmdlet 对已使用加密消息语法 (CMS) 格式加密的内容进行解密。

CMS cmdlet 使用用于消息加密保护的 IETF 标准格式对内容的加密和解密提供支持,如 RFC5652 中所述。

CMS 加密标准采用公钥加密系统,其中用来加密内容的密匙(公匙)和用来解密内容的密匙(私匙)是分离的。 你的公钥可以广泛共享,它不是敏感数据。 如果用此公匙加密了任何内容,只有你的私匙可以解密它。 有关详细信息,请参阅 Public-key cryptography(公钥加密)。

Unprotect-CmsMessage 解密已采用 CMS 格式加密的内容。 可以运行此 cmdlet 来解密通过运行 Protect-CmsMessage cmdlet 加密的内容。 可以通过加密事件日志 ID 号或加密内容的路径指定要解密为字符串的内容。 Unprotect-CmsMessage cmdlet 返回解密的内容。

PowerShell 7.1 中添加了对 Linux 和 macOS 的支持。

示例

示例 1:解密消息

在以下示例中,你将解密位于文本路径 C:\Users\Test\Documents\PowerShell 的内容。 对于所需 To 参数的值,此示例使用用于执行加密的证书的指纹。 解密后的消息“尝试新的 Break All 命令”是结果。

$parameters = @{
  LiteralPath = "C:\Users\Test\Documents\PowerShell\Future_Plans.txt"
  To = '0f 8j b1 ab e0 ce 35 1d 67 d2 f2 6f a2 d2 00 cl 22 z9 m9 85'
}
Unprotect-CmsMessage -LiteralPath @parameters

Try the new Break All command

示例 2:对加密事件日志消息进行解密

以下示例从 PowerShell 事件日志获取加密事件,并使用 Unprotect-CmsMessage 对其进行解密。

$event = Get-WinEvent Microsoft-Windows-PowerShell/Operational -MaxEvents 1 |
    Where-Object Id -eq 4104
Unprotect-CmsMessage -EventLogRecord $event

示例 3:使用管道对加密事件日志消息进行解密

以下示例从 PowerShell 事件日志获取加密事件,并使用 Unprotect-CmsMessage 对其进行解密。

Get-WinEvent Microsoft-Windows-PowerShell/Operational |
    Where-Object Id -eq 4104 |
    Unprotect-CmsMessage

参数

-Content

指定加密字符串或包含加密字符串的变量。

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-EventLogRecord

指定包含 CMS 加密消息的事件日志记录。

Type:PSObject
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-IncludeContext

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-LiteralPath

指定要解密的加密内容的路径。 与 Path 不同,LiteralPath 的值严格按照所键入的形式使用。 不会将任何字符解释为通配字符。 如果路径包括转义符,请将其括在单引号中。 单引号告知 PowerShell 不要将任何字符解释为转义序列。

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Path

指定要解密的加密内容的路径。

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-To

指定一个或多个 CMS 消息收件人,这些收件人使用以下任何格式进行标识:

  • 实际证书(从证书提供程序检索到的)。
  • 包含证书的文件的路径。
  • 指向包含证书的目录的路径。
  • 证书的指纹(用于在证书存储中查找)。
  • 证书的使用者名称(用于在证书存储中查找)。
Type:CmsMessageRecipient[]
Position:1
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

输入

EventLogRecord

String

可以通过管道将包含加密内容的对象传递给此 cmdlet。

输出

String

此 cmdlet 返回未加密的消息。