将私有RSACryptoServiceProvider blob导入CNGKey.Import [英] Import a private RSACryptoServiceProvider blob into CNGKey.Import

查看:211
本文介绍了将私有RSACryptoServiceProvider blob导入CNGKey.Import的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从旧版程序中


再见[] rsaPrivateKeyExport = RSACryptoProvider.ExportCspBlob(true);

bye[] rsaPrivateKeyExport = RSACryptoProvider.ExportCspBlob(true);

这些密钥存储在文件中。

These keys are stored in a file.

作为旧版刷新的一部分,我需要使用CNG RSA密钥。

As part of a legacy refresh, I need to use CNG RSA keys.

类似于读取旧的blob然后进行转换:

So something like reading the old blob and then converting:


CngKey cngPrv = CngKey.Import(rsaPrvKeyExport,
CngKeyBlobFormat.GenericPrivateBlob);

CngKey cngPrv = CngKey.Import(rsaPrvKeyExport, CngKeyBlobFormat.GenericPrivateBlob);

但是我无法使它正常工作吗?

But I cannot get this to work?

如何将旧的Blob类型转换为新的Blob类型?我只使用旧的Blob的一部分吗?

How do I convert the old blob type to the new one? Do I only use parts of the old blob?

密钥长度为2048。

推荐答案

GenericPrivateBlob 是CNG特定的格式,并不意味着尝试任何私人物品。

GenericPrivateBlob is a CNG-specific format, it doesn't mean "try any private thing".

CNG能够使用 https://docs.microsoft.com/zh-cn/windows/desktop/api/Bcrypt/nf-bcrypt-bcryptexportkey

private static readonly CngKeyBlobFormat s_legacyRsaPrivateBlobFormat =
    new CngKeyBlobFormat("CAPIPRIVATEBLOB");

...

byte[] exported;

using (RSACryptoServiceProvider a = new RSACryptoServiceProvider(2048))
{
    exported = a.ExportCspBlob(true);
}

RSA b;

using (CngKey key = CngKey.Import(exported, s_legacyRsaPrivateBlob))
{
    b = new RSACng(key);
}

// This using is broken out here just to show that the constructed object can safely outlive
// the CngKey object that it was created from.
using (b)
{
    ...
}

这篇关于将私有RSACryptoServiceProvider blob导入CNGKey.Import的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆