Вот ошибка, которую получаю, используя .Net 8 с установленным CryptoPro и ЭЦП.
Есть доступ в ЛК по ЭЦП, но не могу прикрутить её к веб-приложению (.Net 8), выдаёт ошибку выполнения.
При замене CpX509Store на X509Store, CpX509Certificate2 на X509Certificate2, CpSignedCms на SignedCms, CpCmsSigner на CmsSigner такая же ошибка.
Завёл issue в dotnet.
Как исправить?
https://github.com/dotnet/runtime/issues/119642//System.Security.Cryptography.CryptographicException: "Could not determine signature algorithm for the signer certificate."
[HttpPost("{data}/{inn}")]
public IActionResult SignInvoice(string data, string inn)
{
// подгоняем ИНН до 12 символов
if (inn.Length < 12)
inn = "".PadLeft(12 - inn.Length, '0') + inn;
using (var x509Store = new CpX509Store(StoreName.My, StoreLocation.LocalMachine))
{
x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
using (CpX509Certificate2 certificate = x509Store.Certificates
.FirstOrDefault(x => x.Subject.Contains(inn, StringComparison.InvariantCultureIgnoreCase)))
{
if (certificate is null)
return NotFound();
}
}
byte[] msgBytes = Encoding.UTF8.GetBytes(data);
var contentInfo = new ContentInfo(msgBytes);
var signedCms = new CpSignedCms(contentInfo, false);
using (var x509Store = new CpX509Store(StoreName.My, StoreLocation.LocalMachine))
{
x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
using (CpX509Certificate2 certificate = x509Store.Certificates
.FirstOrDefault(x => x.Subject.Contains(inn, StringComparison.InvariantCultureIgnoreCase)))
{
if (certificate is null)
return NotFound();
var cmsSigner = new CpCmsSigner(certificate)
{
IncludeOption = X509IncludeOption.EndCertOnly
};
signedCms.ComputeSignature(cmsSigner);
byte[] encodedSignature = signedCms.Encode();
return Ok(Convert.ToBase64String(encodedSignature));
}
}
}
/*
Related StackOverflow article -
https://stackoverflow.co...-not-determine-signature*/
Image Image