RSA:在 .NET 中使用公钥进行解密?
我对 MS .NET 的 RSA 加密/解密功能有疑问:
看来 .NET 不支持使用私钥进行加密并使用相应的公钥进行解密。 (据我了解,这样做会在某种程度上侵犯算法的安全性。)
好的,但是例如当我在构建时签署程序集时,似乎 编译器就是这样做的:“编译器使用来自您的 1024 位私钥对摘要进行加密公钥-私钥对文件。”
那么,如果我无法说服 RSACryptoServiceProvider 使用公钥进行解密,我该如何实现类似编译器的功能呢?
我只想用私钥加密几个字节并用公钥解密,以完成一些非关键任务。如果一个编程极客设法打破这个计划,我就活下去。我只是想防止不懂技术的无名氏四处窥探。
任何对此的建议将不胜感激。
问候 berntie
编辑:建议使用 SignData() 和 verifySign() ,但我只能比较哈希值是否相等。但是,我需要检索加密/签名的原始输入。
I'm having issues with the RSA encryption/decryption capabilities of MS .NET:
It seems, .NET does not support using a private key for encryption and the corresponding public key for decryption. (As I understand, doing it that way round, somehow infringes the security of the algorithm.)
Ok, but for example when I sign an assembly on building, it seems the compiler just does that: "The compiler encrypts the digest using the 1024-bit private key from your public-private key pair file."
So, if I cannot convince the RSACryptoServiceProvider to use a public key for decrypting, how can I achieve something similar like the compiler?
I just want to encrypt a few bytes with my private key and decrypt it with the public key, for some non-critical task. If a programming geek manages to break that scheme, I'll live. I just want to prevent the non-tech-savvy John Doe from snooping around.
Any advice on this would be appreciated.
Greets
berntie
Edit: Usign SignData() and VerifySign() has been suggested, but then I can only compare hashes for equality. However, I need to retrieve the original input that was encrypted/signed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.Net 确实支持它,但该概念称为“签名”并使用 RSACryptoServiceProvider。从技术上讲,正在发生的事情是创建要签名的数据的哈希值,然后使用私钥对该哈希值进行加密。
我认为他们不支持使用私钥任意加密的原因是为了确保代码中良好的安全实践,这样您就不会意外地使用错误的密钥进行加密,或者您不会使用不安全的技术来进行加密签名。
有关示例代码,请参阅 SignData 上的文档。
.Net does support it, but that concept is called "Signing" and uses the SignData() method of RSACryptoServiceProvider. Technically, what's happening is it's creating a hash of the data to be signed, then encrypting that hash with the private key.
I think the reason they don't support arbitrarily encrypting with the private key is to ensure good security practices in your code, so that you don't accidentally encrypt with the wrong key, or that you don't use an insecure technique for making the signature.
See the documentation on SignData for example code.
这是我的代码,仍然有一些缺陷,但在大多数情况下都有效。
我通过Java得到
modulusString
。Here is my code, still has some defect but worked in most situation.
I get
modulusString
by Java.