【发布时间】:2019-09-04 22:45:38
【问题描述】:
我正在使用带有 .NET Core 2.2 的 Mimekit。我正在尝试使用 RSASSA-PSS 对消息进行签名,但找不到为 RSASignaturePadding 设置签名算法的方法。更改 DigestAlgorithm 会导致使用错误的填充。
如何修复此代码 sn-p 以使用 RSASSA-PSS 而不是默认填充?
public MimeMessage SignMessage(MimeMessage message, MailboxAddress address)
{
CryptographyContext.Register(typeof(WindowsSecureMimeContext));
using (var ctx = new WindowsSecureMimeContext(StoreLocation.LocalMachine))
{
X509Certificate2 cert = null;
string thumbprint = "<myThumbprint>";
var machineStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
machineStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection machineCerts = machineStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (machineCerts.Count == 1)
{
cert = machineCerts[0];
}
if (cert != null)
{
CmsSigner signer = new CmsSigner(cert)
{
DigestAlgorithm = DigestAlgorithm.Sha256
};
message.Body = MultipartSigned.Create(ctx, signer, message.Body);
}
}
return message;
}
【问题讨论】: