【发布时间】:2016-03-28 00:00:52
【问题描述】:
我正在生成密钥对并将它们存储在 xml 文件中使用
ToXmlString(true);
我需要将密钥大小设置为 2048 根据 MSDN,唯一可以做到这一点的地方是 RSACryptoServiceProvider 的构造函数
private void AssignParameter(ProviderType providerType)
{
CspParameters cspParams;
cspParams = new CspParameters((int)providerType);
cspParams.KeyContainerName = RSAEncryption.containerName;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
cspParams.KeyNumber = (int)KeyNumber.Exchange;
this.rsa = new RSACryptoServiceProvider(2048, cspParams);
}
当我使用检查密钥大小时
int x = this.rsa.KeySize;
我总是得到 1024 那么这里有什么问题吗??
【问题讨论】:
-
你的代码对我有用,我得到了 2048。你为 providerType 传递了什么?我在创建 cspParams 时使用了值 1 (PROV_RSA_FULL)。我还将自己的字符串传递给 cspParams.KeyContainerName。
-
我正在使用值为 1 的 PROV_RSA_FULL 以及我的 KeyContainerName 属性的一个字符串!
-
我得到“消息对象已经存在。”
标签: c# rsa encryption-asymmetric private-key