PKCS -导出到可读格式

本文关键字:格式 PKCS | 更新日期: 2023-09-27 18:04:50

我必须使用PKCS对消息进行签名和加密:

EnvelopedCms envelopedCms = ...
// Add recipients
envelopedCms.Encrypt(recip1);
//
msg = envelopedCms.Encode();

我需要的结果格式是:

-----BEGIN PKCS7-----
base64 encoded msg
-----END PKCS7-----

你知道如何在c#/.net中导出这种格式吗?

谢谢

PKCS -导出到可读格式

这是你需要的吗?(从这篇文章)

SignedCms signedCms = new SignedCms();
resultString = resultString.Replace("'n", "").Replace("-----BEGIN PKCS7-----", "").Replace("-----END PKCS7-----", "");
signedCms.Decode(Convert.FromBase64String(resultString));

要在c# .NET中将字符串编码为base64字符串,可以这样做:(我已经添加了这个,因为你的问题不清楚,但状态"base64编码的msg")

// Get the bytes.
var bytes = System.Text.Encoding.UTF8.GetBytes(yourString);
return System.Convert.ToBase64String(bytes);