我已经为此苦苦挣扎了好几天,RFC 2315有点难以理解。EnvelopedCms解密不适用于Azure密钥保管库
我想实现我自己的EnvelopedCms.Decrypt()
版本,让我能以正确的方式使用Azure的主要跳马的证书操作UnwrapKey
和/或Decrypt
一个PKCS#7消息(CMS对象)。我在.Net中使用EnevelopedCms给Decode
留言,然后我尝试Decrypt
EnvelopedCms.ContentInfo.Content
。
这是我试图做的;
public static async Task<byte[]> DecryptCustom(string certificateId, string encryptedBase64Content)
{
var bytes = Convert.FromBase64String(encryptedBase64Content);
var contentInfo = new ContentInfo(bytes);
var envelopedCms = new EnvelopedCms(contentInfo);
envelopedCms.Decode(bytes);
// envelopedCms.Decrypt() <-- no go. Can't extract certificate from Key Vault
// My (naive) attempt to decrypt CMS content using Azure Key Vault certificates
byte[] decryptedContent;
using (var client = new KeyVaultClient(GetKeyVaultToken))
{
var decryptionresult = await client.DecryptAsync(GetKeyUrl(certificateId), "RSA1_5", envelopedCms.ContentInfo.Content);
decryptedContent = decryptionresult.Result;
}
return decryptedContent;
}
我当时希望可以那么容易,但是它给了我下面的错误;
无法用此密钥解密指定的值。
我在RFC 2315中读了一些关于八位字节的内容,所以在我解密之前,流(字节数组)可能需要重新排序。我是否需要打开一些对称密钥才能解密真正的有效负载?我在这里薄冰。
我不是密码专业人员,所以我可能错过了一些明显的东西。我希望有人知道在这种情况下该怎么做,因为我真的想让我的证书保存在密钥保管库(HSM)中
谢谢!这帮助我解决了这个问题。我现在可以使用Azure密钥保管库中的专用证书来解密CMS对象! – Frode