azure - 使用 Azure Keyvault SignData 进行 SignedXml

标签 azure .net-core cryptography

我知道如何使用 SignedXml 签署 XML 文档 ( https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.xml.signedxml?view=dotnet-plat-ext-6.0 )

我知道如何使用 Azure KeyVault API 对数据进行签名,以便私钥保持安全 ( https://learn.microsoft.com/en-us/dotnet/api/azure.security.keyvault.keys.cryptography.cryptographyclient.signdata?view=azure-dotnet )

现在我想将两者结合起来,使用 SignedXml(或创建相同的结果),使用保管库中的 key 而不提取私钥。

尝试设置如下所示的两个值似乎不正确

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
        <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
        <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
        <Reference URI="">
            <Transforms>
                <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
            <DigestValue>...</DigestValue>
        </Reference>
    </SignedInfo>
    <SignatureValue>...</SignatureValue>
</Signature>
var digestValue = new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(xmlDoc.OuterXml));
var signatureValue = new CryptographyClient().SignData(SignatureAlgorithm.RS256, digestValue);

最佳答案

您需要实现继承自 System.Security.Cryptography.RSA 的自定义类类,在其实现中使用 KeyVault API,然后使用自定义类的实例作为 SigningKey .

您可以自己实现,也可以使用 RSAKeyVaultProvider图书馆。

关于azure - 使用 Azure Keyvault SignData 进行 SignedXml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71925022/

相关文章:

azure - Microsoft Azure 与 "regular"虚拟主机相比

java - PRNG 在 java 中按键播种

python - 实现离散对数的 Pollard Rho 算法

asp.net-core - 如何使用我的自定义异常中间件捕获 ASP.NET Core (3.1) URL 解析错误?

c# - Rfc2898DeriveBytes 的输出取决于什么以及盐应该如何处理?

azure - 在 Azure 中维护以前版本的 API 的最佳方法是什么?

azure - 是否可以在 Azure DevOps 中显示 ARM 部署的进度?

javascript - Azure 事件中心 : How to grant SAS tokens to Javascript publishers (running in browser)?

azure - 如何通过 Entity Framework 核心代码优先方法从 cosmosdb 集合中设置分区键?

c# - 如果在 'await' 之后抛出,则从任务中抛出的异常被吞没