如何使用Mono框架和BouncyCastle API生成CMS(加密消息语法)?

如何使用Mono框架和BouncyCastle API生成CMS(加密消息语法)?,mono,cryptography,bouncycastle,Mono,Cryptography,Bouncycastle,我有PKCS12格式的证书,需要生成CMS签名加密消息语法。由于Mono框架没有一个完整实现的System.Security.Cryptography程序集,所以我尝试将Bouncy Castle API用于C 因此,使用BouncyCastle,我需要编写一个与我在DOTNET上编写的代码不同的代码 DOT NET上的代码如下所示: X509Certificate2 crt = new X509Certificate2(); byte[] crtBytes = [ certificate i

我有PKCS12格式的证书,需要生成CMS签名加密消息语法。由于Mono框架没有一个完整实现的System.Security.Cryptography程序集,所以我尝试将Bouncy Castle API用于C

因此,使用BouncyCastle,我需要编写一个与我在DOTNET上编写的代码不同的代码

DOT NET上的代码如下所示:

X509Certificate2 crt = new X509Certificate2();

byte[] crtBytes = [ certificate in the format PKCS12 (certificate + private key) obtained using FileStream class]

crt.Import(crtBytes, "123456", X509KeyStorageFlags.DefaultKeySet);

Encoding msgCodificado = Encoding.UTF8;

byte[] msgBytes = msgCodificado.GetBytes(xmlTRA.OuterXml); // xmlTRA.OuterXml is the data to sign

ContentInfo pkcsContentInfo = new ContentInfo(msgBytes);

SignedCms cms = new SignedCms(pkcsContentInfo);
CmsSigner firmante = new CmsSigner(crt);

firmante.IncludeOption = X509IncludeOption.EndCertOnly;
cms.ComputeSignature(firmante); // ---> throw an cryptografy exception with MONO

byte[] firma = cms.Encode();
firmaB64 = Convert.ToBase64String(firma);

有人知道如何使用Bouncy Castle API为C编写替代代码吗?

Org.bounchycastle.Pkcs有用于处理PKCS12存储的类。 Org.bounchycastle.Cms有用于处理Cms消息的类

源代码中有相应的测试类,显示了使用的基本知识,例如Pkcs12StoreBuilder和CmsSignedDataGenerator