我已經爲此苦苦掙扎了好幾天,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