使用文件中的私钥解密 C# 或 .NET 中的 p7m 文件
希望有人可以帮助我编写代码,因为我花了 3 个月的时间编写代码,但没有成功。我几乎尝试了互联网上的所有内容,但没有任何效果。
问题:我加密了文件 p7m(大小 158KB)(它是加密文本)。我在文件 pfx 中有证书,密码为“a”。该证书中包含解密 p7m 文件所需的公钥。
我需要一些可以读取 xyyv.p7m 文件、用公钥解密并将其另存为 XYZ.xyz 的东西,
我没有在这里放置任何我的代码,以免让您感到困惑。谢谢
Hopefully someone can help me with code because I am working on it 3 months without any success. I tried almost anything from internet but nothing does not work.
Problem: I have encrypted file p7m (size 158KB) (it is crypted text). I have certificate in file pfx, under password "a". In this certificate is the public key which is needed to decrypt p7m file.
I need something that will read xyyv.p7m file, decrypt it with public key, and save it as XYZ.xyz
I do not put here any my code to do not confuse you. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PKCS#7 结构可能非常混乱(对于大多数 ASN.1 结构来说确实如此)。如果我们不知道使用什么来生成此文件,则无法给出太多具体建议。
一般来说,
System 中有用于读取它们的代码。 Security.Cryptography.Pkcs
,但很容易创建无法正确处理的文件(有效或无效)。如果它们是使用不同的工具生成的,那就更是如此。Mono 在
Mono.Security
内提供了类,阅读它们。它们是非常低级的 API(带有一些帮助程序),因此从理论上讲,它们应该能够读取任何内容......只要您不介意对格式本身的处理进行编码。其他库,BouncyCastle 会提供类似的(低级或高级)API 来处理 PKCS# 7 个文件。
A PKCS#7 structure can be very messy (and that's actually true for most ASN.1 structures). There's not much specific advice that can be given if we don't know what was used to produce this file.
In general there's code for reading them in
System.Security.Cryptography.Pkcs
but it's easy to create files (valid or invalid) that won't be processed correctly. Even more if they were generated using different tools.Mono provides classes, inside
Mono.Security
, to read them. They are very low-level API (with some helpers) so, in theory, they should be able to read anything... as long as you don't mind coding the processing your format itself.Other libraries, BouncyCastle comes to mind, will offer similar (low or high level) API to process PKCS#7 files.