加密库?

发布于 2024-07-05 02:51:29 字数 542 浏览 4 评论 0原文

我的任务是在公司项目中用 C# 实现 PKI 库,但一直找不到它的良好实现。 似乎有多个库,并且许多损坏的链接指向已被删除的 MSDN 库。 我见过人们使用 Crypt32.dll、人们构建自己的库、人们使用 P/Invoke 访问系统证书存储、人们扩展内置库、根本不适用于 C# 的示例(例如 Java 示例)、和商业图书馆。

我的问题是,最推荐哪种实现/库来进行简单的数据加密/解密?

作为我计划使用它做的一些背景,我只需要使用私钥(.pfx)加密消息,并使用公钥(.cer)解密。 在此级别的项目中不需要消息签名和身份验证,尽管将来可能需要。 我看到了有关加密长度的参考,这让我感到不安。 我们需要能够加密任何长度的消息(当然,在合理的范围内!)。 这是我需要担心的事情吗?如果是的话,有什么办法可以处理吗?

如果可能的话,我宁愿不要在 Windows 证书管理器中存储公钥/私钥,但如果它使实现变得更加简单,那就这样吧。

我意识到 PKI 和加密是一个庞大而复杂的主题,但我还是希望有一个相对简单的库......(可以希望,对吧?)

谢谢!

I have been tasked with implementing a PKI library in C# for a company project, and have been unable to find a good implementation of it. There appear to be multiple libraries, and many broken links pointing to MSDN libraries that have been removed. I've seen people using Crypt32.dll, people building their own libraries, people using P/Invoke to access system certificate stores, people extending the built-in libraries, examples that simply don't apply to C# (e.g. Java examples), and commercial libraries.

My question is, which implementation/library is most recommended for simple encryption/decryption of data?

As some background for what I plan to do with it, I simply need to encrypt messages using a private key (.pfx), and decrypt with public keys (.cer). Message signing and authentication isn't required at this level of the project, although it may be in future.
I have seen reference to encryption lengths which make me uneasy. We need to be able to encrypt any length message (within reason, of course!). Is this something I need to worry about, and if so, is there a way to deal with it?

I would prefer not to store public/private keys in the windows certificate manager if at all possible, but if it makes implementation significantly simpler, so be it.

I realize PKI and encryption is a large and complex subject, but I'm hoping for a relatively simple library anyway... (one can hope, right?)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铜锣湾横着走 2024-07-12 02:51:29

是的,内置类有什么问题呢?

如果您不想使用 Windows 证书存储,您可以使用类似的东西,

RSACryptoServiceProvider rscp = new RSACryptoServiceProvider();
rscp.FromXmlString("<RSAKeyValue><Modulus>key data gere</Modulus><Exponent></Exponent></RSAKeyValue>");

但不确定这对于私钥来说是个好主意。

这里有一个关于该主题的很好的教程

Yes, what's wrong with built-in classes?

And if you don't want to use Windows certificate store you can use something like this

RSACryptoServiceProvider rscp = new RSACryptoServiceProvider();
rscp.FromXmlString("<RSAKeyValue><Modulus>key data gere</Modulus><Exponent></Exponent></RSAKeyValue>");

Not sure that this is a good idea for private keys, though.

There's a good tutorial on the subject here

我是有多爱你 2024-07-12 02:51:29

好吧,您没有提到内置类不能满足您的需求,那么 System.Security.Cryptography.RSACryptoServiceProvider

它有大量合格的方法来非对称加密/解密流。

有几个教程/指南可以引导您:

通过 Google 可以找到无数更多内容

更新:关于长度限制,如果您只是在双方(加密和解密)上实现相同的缓冲区算法,那么应该不会有任何问题。

Update2:是的,我的示例是RSACryptoProvider,但您可以使用从System.Security.Cryptography.AmetryAlgorithm,如果您想要公钥/私钥解决方案。 或者建立你自己的......或者也许不是:)

Well, you did not mention that the built-in class doesn't cover your need, so how about System.Security.Cryptography.RSACryptoServiceProvider?

It has a large set qualified ways to asymmetrically encrypt/decrypt streams.

There are several tutorial/guides to take you along the way:

There are countless more to be found through Google.

Update: About the length-restrictments, it's should not be any problems if you just implement the same buffer-algorithm on both sides, encryption and decryption.

Update2: Yes, my example was RSACryptoProvider, but you can use any class that derives from System.Security.Cryptography.AsymmetricAlgorithm, if you want a public/private key-solution. Or build your own... or maybe not :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文