我正在尝试创建一个将使用 XML 文档中的数据的 powershell 脚本。但是,在做任何工作之前,我需要通过验证签名来验证 XML 未被篡改。
我有用于以 PEM 格式签署 XML 的证书的公钥副本,但我不知道如何让 powershell 使用该证书。
我已经开始让它工作的关闭是以下代码......
$Path = "data.xml"
$Xmldata = new-object Xml.XmlDocument
$Xmldata.PreserveWhitespace = $true
$Xmldata.Load($Path)
add-type -AssemblyName system.security
$SignedXml = New-Object System.Security.Cryptography.Xml.SignedXml -ArgumentList $Xmldata
$XmlNodeList = $Xmldata.EntitiesDescriptor.Signature
$XmlNodeList
$SignedXml.LoadXml($XmlNodeList)
$CertPath = "cert.pem"
$Check = $SignedXml.CheckSignature($CertPath, $true)
但是,当它运行时,我得到以下异常......
使用“2”参数调用“CheckSignature”的异常:“无法为提供的签名算法创建SignatureDescription。” 在 line:34 char:1 + $Check = $SignedXml.CheckSignature($CertPath, $true) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : CryptographicException
任何帮助,将不胜感激。谢谢!