RSACryptoProvider 为相同的 CspParameter ContainerName 重复生成相同的密钥
我是 .NET CryptoProvider 领域的新手,并且对我所看到的有关 RSACryptoProvider 重复创建相同密钥的情况有点担心。 我正在使用容器,因为我将密钥存储到服务器上的文件中,就像这样(我在创建之后导出 CspBlob 并稍后重新导入)...
_cp = new CspParameters { KeyContainerName = ContainerName };
在这种情况下,ContainerName 有一个硬编码值,我引用了容器由. 令我困扰的是,当我创建 RSACryptoProvider 并扩展密钥对时,生成的密钥值始终相同!
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(RSAKeySize, _cp);
如果我更改容器的名称,密钥就会更改。创建 RSACryptoProvider 时,除了容器名称之外,还必须有其他随机源,对吧?否则,这会使容器的名称成为密码,这不是我的意图。
I'm new to the .NET CryptoProvider space, and am a little concerned by what I have seen regarding the repeated creation of the same key by the RSACryptoProvider.
I am using a container because I am storing the key off to file on the server, like so (I export the CspBlob subsequent to this creation and reimport it later)...
_cp = new CspParameters { KeyContainerName = ContainerName };
In this case the ContainerName has a hardcoded value that I reference the container by.
What's bothering me is that when I create the RSACryptoProvider, and by exentsion the key pair, the generated key values are always the same!
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(RSAKeySize, _cp);
If I change the name of the container, the key changes. There must be SOME other source of randomness than the container name when you create an RSACryptoProvider, right? Otherwise that makes the name of the container a password, which is not my intention.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是容器的名称,而不是生成器的名称。
如果您每次都需要不同的密钥,只需创建一个新的 CryptoServiceProvider 而不引用容器(==存储的密钥对)。
It's the name of a container, not of a generator.
If you want different keys each time, just create a new CryptoServiceProvider w/o referencing a container( == stored key-pair).
以下代码将删除与容器名称相关的键(如果存在)。
删除密钥后;您可以创建一个具有相同容器名称的新容器,您将获得新的随机密钥。
Following code will delete the key(if exist) related with the containername.
After you delete the key; you can create a new one with the same conatiner name and you will get new random key.