如何加密导出 CngKey 到 PKCS#8?
static void Main(string[] args)
{
CngKeyCreationParameters ckcParams = new CngKeyCreationParameters()
{
ExportPolicy = CngExportPolicies.AllowExport,
KeyCreationOptions = CngKeyCreationOptions.None,
KeyUsage = CngKeyUsages.AllUsages,
};
ckcParams.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(2048), CngPropertyOptions.None));
myCngKey = CngKey.Create(CngAlgorithm.Rsa, "theCngKey", ckcParams);
byte[] privatePlainTextBlob = myCngKey.Export(CngKeyBlobFormat.Pkcs8PrivateBlob);
}
将 ExportPolicy 设置为 AllowPlainTextExport 允许导出 key ,但只能以纯文本形式导出。我想创建一个使用对称 key 加密的 PCKS8 blob。
谢谢
最佳答案
由于 CngKey.Export
不接受密码,您必须手动 P/Invoke 到 NCryptExportKey ,提供 NCRYPTBUFFER_PKCS_SECRET 值(Unicode/UCS-2 编码密码,带有显式空终止符)。
http://source.dot.net/#System.Security.Cryptography.Cng/Common/System/Security/Cryptography/ECCng.ImportExport.cs,8b172741466df7a1可以用作构建参数列表的示例。这不好玩。
关于c# - 使用加密 c# 在 PKCS8 中导出 CngKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44305299/