{"id":405219,"date":"2024-06-29T18:11:36","date_gmt":"2024-06-29T18:11:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=405219"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=405219","title":{"rendered":"<span>.NET 7 \u043f\u0440\u043e\u0442\u0438\u0432 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u0441\u0432\u0435\u0436\u0435\u043c .NET 7 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432. \u0420\u0430\u043d\u0435\u0435, \u0432 .NET Framework  \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0413\u041e\u0421\u0422 (CryptoPro CSP, ViPNet CSP \u0438 \u043f\u0440.), \u0448\u043b\u0430 &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;. \u041f\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b \u043a\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.cryptography.pkcs.signedcms?view=dotnet-plat-ext-7.0\" rel=\"noopener noreferrer nofollow\"><code>SignedCms<\/code><\/a>, \u0438 voil\u00e0:<\/p>\n<pre><code>System.Security.Cryptography.CryptographicException: 'Could not determine signature algorithm for the signer certificate.' <\/code><\/pre>\n<p>\u042f\u0441\u043d\u043e-\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u043d\u043e\u0432\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043f\u043e\u043c\u043d\u043e\u0436\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u043d\u043e\u043b\u044c. <\/p>\n<h3>\u0427\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a?<\/h3>\n<p>\u041f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 .NET \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u044b\u0432\u0435\u043b\u0430 \u043d\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/26053\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0433, \u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u0443\u0436\u0435 \u043f\u044f\u0442\u044c \u043b\u0435\u0442<\/a>. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 .NET Team \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0413\u041e\u0421\u0422 \u0420 34.10-2012 \u0434\u0430\u0440\u043e\u043c \u043d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0431\u0438\u043b\u0438.<\/p>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/h3>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0431\u044b\u043b\u0430 &#171;\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0436\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0435\u043d\u0441\u043e\u0440\u0441, \u0437\u0430\u043f\u0438\u043b\u0438 \u0441\u0430\u043c&#187;. \u041d\u043e \u0432\u044b\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0451\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u043f\u0443\u0433\u043d\u0443\u043b \u0434\u0435\u043b\u0430\u0442\u044c &#171;\u0441 \u043a\u043e\u043b\u0451\u0441&#187;, \u0434\u0430 \u0438 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/docs\/project\/api-review-process.md\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c API Proposal<\/a> &#8212; \u0442\u043e\u0442 \u0435\u0449\u0451 \u043a\u0432\u0435\u0441\u0442.<\/p>\n<p>\u0418\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 <a href=\"https:\/\/github.com\/bcgit\/bc-csharp\" rel=\"noopener noreferrer nofollow\">Bouncy Castle<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u043f\u043e\u0441\u043b\u0435 <a href=\"https:\/\/github.com\/bcgit\/bc-csharp\/issues\/231\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0443\u0445\u043b\u0435\u0442\u043d\u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f<\/a> \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e PR \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u0434\u043b\u044f CMS, \u0442\u043e\u0436\u0435 \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043e\u0442\u043f\u0430\u043b, \u0442\u0430\u043a \u043a\u0430\u043a \u0441 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0436\u0435\u043b\u0430\u0435\u0442 (\u0438\u043b\u0438 \u044f \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b).<\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u0434\u0435\u0431\u0440\u044f\u0445 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u043c\u043e\u0439 \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0443\u0436\u0435 \u0432 \u0434\u0430\u043b\u0451\u043a\u043e\u043c 2015 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u043d\u0430 \u0433\u043e\u043b\u043e\u043c WinAPI. \u0410 \u0442\u0430\u043a \u043a\u0430\u043a P\/Invoke \u0438\u0437 .NET <em>\u043f\u043e\u043a\u0430<\/em> \u043d\u0435 \u0432\u044b\u043f\u0438\u043b\u0438\u043b\u0438, \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c, \u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0438 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u043e\u043c \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u044b \u0432\u0435\u0447\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0438\u043d\u0433\u0430, \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0448\u043b\u0430 \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u043e\u043b\u043e\u0447\u0435\u043a \u0434\u043b\u044f CryptoAPI.<\/p>\n<h3>\u0414\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 WinAPI<\/h3>\n<p>\u0412 WinAPI \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/seccrypto\/low-level-messages\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a> \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440. \u0412\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Microsoft, \u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0443\u043b\u044f \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u0438\u043b\u0438\u0439 \u0438 \u043e\u0431\u043e\u0439\u0442\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439. \u0414\u0430\u043b\u0435\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0443\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u042d\u041f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0434\u0430\u043b\u0435\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/AntoineLarine\/NetWinapiCms\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<p><strong>Disclaimer<\/strong>. \u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e unsafe-\u043a\u043e\u0434\u0430 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043d\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 C#, \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>Span&lt;T><\/code>. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0435 &#171;C# &#8212; \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u044f\u0437\u044b\u043a&#187; \u0438 \u0442.\u043f., \u043d\u043e \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0448\u043a\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0439 \u043b\u0438\u0448\u043d\u0438\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043a\u0443\u0447\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u043b\u0438\u043d\u0433\u0435.<\/p>\n<h4>\u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u043b\u0438\u0448\u043d\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptacquirecertificateprivatekey\" rel=\"noopener noreferrer nofollow\"><code>CryptAcquireCertificatePrivateKey<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentoencode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToEncode<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0432\u043b\u0435\u0447\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0438 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0430\u0439\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam<\/code><\/a>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0443\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0443:<\/p>\n<pre><code class=\"cs\">\/\/ acquire certificate private key var flags = (silent ? CRYPT_ACQUIRE_SILENT_FLAG : 0U) | CRYPT_ACQUIRE_COMPARE_KEY_FLAG; CryptAcquireCertificatePrivateKey(certificate.Handle, flags, 0, out var hProvider, out var dwKeySpec, out var pfCallerFreeProv).VerifyWinapiTrue(); try { ... } finally { if (pfCallerFreeProv) if (dwKeySpec == CERT_NCRYPT_KEY_SPEC) NCryptFreeObject(hProvider); else CryptReleaseContext(hProvider, 0); } <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptacquirecertificateprivatekey\" rel=\"noopener noreferrer nofollow\"><code>CryptAcquireCertificatePrivateKey<\/code><\/a> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0443, \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0438 \u0444\u043b\u0430\u0433 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0436\u0435\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 <code>try\/finally<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435, \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c \u043c\u0443\u0441\u043e\u0440\u0430 \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0438 \u0432\u0441\u0451 \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0430\u0439\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b-\u0445\u0435\u043b\u043f\u0435\u0440\u044b <code>VerifyWinapiTrue()<\/code> \u0438 <code>VerifyWinapiNonzero()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u0446\u0438\u0439 WinAPI \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>Win32Exception<\/code> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/errhandlingapi\/nf-errhandlingapi-getlasterror\" rel=\"noopener noreferrer nofollow\"><code>GetLastError<\/code><\/a>.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441 \u0432 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u0432\u044b\u0448\u0435 &#8212; \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u043b\u0430\u0433\u0430 <code>CRYPT_ACQUIRE_SILENT_FLAG<\/code>. \u041e\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u043e\u043a\u043e\u043d \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c&#187; \u0438\u043b\u0438 &#171;\u0432\u0432\u0435\u0434\u0438\u0442\u0435 PIN-\u043a\u043e\u0434 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430&#187;, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0438\u0437 \u0441\u043b\u0443\u0436\u0431\u044b. \u042d\u0442\u043e\u0442 \u0444\u043b\u0430\u0433 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043e\u043a\u043d\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u044c PIN-\u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043c\u043e\u0433 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">if (pin.Length > 0) { \/\/ set PIN-code for the private key var asciiPinLength = Encoding.ASCII.GetByteCount(pin); var asciiPin = stackalloc byte[asciiPinLength + 1]; Encoding.ASCII.GetBytes(pin, new Span&lt;byte>(asciiPin, asciiPinLength)); if (dwKeySpec == AT_KEYEXCHANGE) CryptSetProvParam(hProvider, PP_KEYEXCHANGE_PIN, (nint)asciiPin, 0).VerifyWinapiTrue(); else if (dwKeySpec == AT_SIGNATURE) CryptSetProvParam(hProvider, PP_SIGNATURE_PIN, (nint)asciiPin, 0).VerifyWinapiTrue(); } <\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e PIN-\u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0431\u0430\u0439\u0442\u043d\u043e\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 ASCII (\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0439 PIN?).<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432, \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u0435 \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">\/\/ acquiring certificate context var certContext = new ReadOnlySpan&lt;CERT_CONTEXT>(certificate.Handle.ToPointer(), 1); var signerCertBlob = new CRYPT_INTEGER_BLOB { cbData = certContext[0].cbCertEncoded, pbData = certContext[0].pbCertEncoded };  \/\/ prepare CMSG_SIGNER_ENCODE_INFO structure var signerInfo = new CMSG_SIGNER_ENCODE_INFO(); signerInfo.cbSize = (uint)Marshal.SizeOf(signerInfo); signerInfo.pCertInfo = certContext[0].pCertInfo; signerInfo.hKey = hProvider; signerInfo.dwKeySpec = dwKeySpec; signerInfo.HashAlgorithm.pszObjId = (nint)digestOidRaw;  \/\/ prepare CMSG_SIGNED_ENCODE_INFO structure var signedInfo = new CMSG_SIGNED_ENCODE_INFO(); signedInfo.cbSize = (uint)Marshal.SizeOf(signedInfo); signedInfo.cSigners = 1; signedInfo.rgSigners = (nint)(&amp;signerInfo); signedInfo.cCertEncoded = 1; signedInfo.rgCertEncoded = (nint)(&amp;signerCertBlob);  \/\/ create CMS var hMsg = CryptMsgOpenToEncode(MsgEncodingTypes.X509_ASN_ENCODING | MsgEncodingTypes.PKCS_7_ASN_ENCODING, detachedSignature ? CMSG_DETACHED_FLAG : 0U, MsgType.CMSG_SIGNED, (nint)(&amp;signedInfo), null, 0).VerifyWinapiNonzero(); try { ... } finally { CryptMsgClose(hMsg); } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0437\u044e\u043c\u0438\u043d\u043a\u0430 \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.cryptography.x509certificates.x509certificate.handle?view=net-7.0\" rel=\"noopener noreferrer nofollow\"><code>X509Certificate.Handle<\/code><\/a> \u0443\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u043d\u0430 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/ns-wincrypt-cert_context\" rel=\"noopener noreferrer nofollow\"><code>CERT_CONTEXT<\/code><\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043a \u0442\u0438\u043f\u0443 <code>ReadOnlySpan&lt;CERT_CONTEXT><\/code> \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u043c\u0430\u0440\u0448\u0430\u043b\u043b\u0438\u043d\u0433\u0430.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0444\u043b\u0430\u0433 <code>CMSG_DETACHED_FLAG<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentoencode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToEncode<\/code><\/a>. \u0415\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c, \u0442.\u0435. CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0441\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435 \u0441 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f\u0432\u043d\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgclose\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgClose()<\/code><\/a>.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438. \u0412\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c:<\/p>\n<pre><code class=\"cs\">\/\/ add, hash, and sign the data fixed (byte* pData = data) CryptMsgUpdate(hMsg, (nint)pData, (uint)data.Length, true).VerifyWinapiTrue(); <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0438\u0437 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">\/\/ extract signed CMS var cmsLength = 0; CryptMsgGetParam(hMsg, CMSG_CONTENT_PARAM, 0, 0, ref cmsLength).VerifyWinapiTrue(); var cms = new byte[cmsLength]; fixed (byte* pSignature = cms) CryptMsgGetParam(hMsg, CMSG_CONTENT_PARAM, 0, (nint)pSignature, ref cmsLength).VerifyWinapiTrue(); <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u043e \u043a\u0430\u043d\u043e\u043d\u0443, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0434\u0432\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 CryptoAPI. \u041f\u0435\u0440\u0432\u044b\u0439 &#8212; \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 <code>cms<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <code>.sig<\/code>, \u0438 \u0432\u0441\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u041a\u0440\u0438\u043f\u0442\u043e-\u0410\u0420\u041c \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a &#171;\u043e\u0431\u044b\u0447\u043d\u0443\u044e&#187; \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c.<\/p>\n<h4>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438<\/h4>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WinAPI \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0435\u0451 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u0438\u0437-\u0437\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043d\u0435 \u043f\u0440\u043e\u0449\u0435 \u043b\u0438 \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430?) \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc5652.html\" rel=\"noopener noreferrer nofollow\">PKCS #7<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0435\u0439 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/CAdES\" rel=\"noopener noreferrer nofollow\">CAdES<\/a>.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432), \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f \u0432 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438, \u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0442\u0430\u043c\u043f\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0418 \u0432\u043d\u043e\u0432\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043e\u0431\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentodecode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToDecode<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-certopenstore\" rel=\"noopener noreferrer nofollow\"><code>CertOpenStore<\/code><\/a> \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0432\u0441\u0435 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b, \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u0434\u043f\u0438\u0441\u044c. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam(..., CMSG_SIGNER_COUNT_PARAM, ...)<\/code><\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0435\u0439 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u0430 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam(..., CMSG_SIGNER_CERT_ID_PARAM, ...)<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 5, \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-certfindcertificateinstore\" rel=\"noopener noreferrer nofollow\"><code>CertFindCertificateInStore(..., CERT_FIND_CERT_ID, ...)<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgcontrol\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgControl(...,  CMSG_CTRL_VERIFY_SIGNATURE_EX, ...)<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u043f\u0443\u0442\u0451\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-certgetcertificatechain\" rel=\"noopener noreferrer nofollow\"><code>CertGetCertificateChain()<\/code><\/a>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432 \u043d\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b:<\/p>\n<pre><code class=\"cs\">var hMsg = CryptMsgOpenToDecode(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, detachedSignature ? CMSG_DETACHED_FLAG : 0U, 0, 0, 0, 0) .VerifyWinapiNonzero(); try { \/\/ load signed CMS fixed (byte* pCms = cms) CryptMsgUpdate(hMsg, (nint)pCms, (uint)cms.Length, true).VerifyWinapiTrue(); if (detachedSignature) { if (data.Length > 0) \/\/ load source data fixed (byte* pData = data) CryptMsgUpdate(hMsg, (nint)pData, (uint)data.Length, true).VerifyWinapiTrue(); else throw new ArgumentException(\"The data must be specified for verifying a detached signature.\", nameof(data)); } ... } finally { CryptMsgClose(hMsg); }  <\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>finally<\/code> \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u0438\u0437 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"cs\">\/\/ extract all included certificates from the CMS as cert store var hCertStore = CertOpenStore(1, 0, 0, 0, hMsg).VerifyWinapiNonzero(); try { ... } finally { CertCloseStore(hCertStore, CERT_CLOSE_STORE_FORCE_FLAG); } <\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>CERT_CLOSE_STORE_FORCE_FLAG<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u044f\u0432\u043d\u044b\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"cs\">\/\/ determine signer count var signerCount = 0U; var signerCountSize = Marshal.SizeOf(signerCount); CryptMsgGetParam(hMsg, CMSG_SIGNER_COUNT_PARAM, 0, (nint)(&amp;signerCount), ref signerCountSize).VerifyWinapiTrue(); if (signerCount == 0) throw new Win32Exception(CRYPT_E_NO_SIGNER); <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u0430 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442:<\/p>\n<pre><code class=\"cs\">\/\/ extract CERT_ID nint pCertContext = 0; var certIdLength = 0; CryptMsgGetParam(hMsg, CMSG_SIGNER_CERT_ID_PARAM, signerIndex, 0, ref certIdLength).VerifyWinapiTrue(); var certIdRaw = ArrayPool&lt;byte>.Shared.Rent(certIdLength); try { fixed (byte* pCertId = certIdRaw) { CryptMsgGetParam(hMsg, CMSG_SIGNER_CERT_ID_PARAM, 0, (nint)pCertId, ref certIdLength).VerifyWinapiTrue(); pCertContext = CertFindCertificateInStore(hCertStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_CERT_ID, (nint)pCertId, 0); if (pCertContext == 0) { var error = Marshal.GetLastWin32Error(); if (error == CRYPT_E_NOT_FOUND) throw new Win32Exception(CRYPT_E_SIGNER_NOT_FOUND); else throw new Win32Exception(error); } } ... } finally { ArrayPool&lt;byte>.Shared.Return(certIdRaw, true); } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u043d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"cs\">\/\/ validate signature var vsp = new CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA(); vsp.cbSize = (uint)Marshal.SizeOf(vsp); vsp.dwSignerIndex = signerIndex; vsp.dwSignerType = CMSG_VERIFY_SIGNER_CERT; vsp.pvSigner = pCertContext; CryptMsgControl(hMsg, 0, CMSG_CTRL_VERIFY_SIGNATURE_EX, (nint)(&amp;vsp)).VerifyWinapiTrue(); <\/code><\/pre>\n<p>\u0418, \u0432 \u043a\u043e\u043d\u0446\u0435, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">\/\/ verify certificates nint pChainContext = 0; var chainParams = new CERT_CHAIN_PARA(); chainParams.cbSize = (uint)Marshal.SizeOf(chainParams); try { CertGetCertificateChain(HCCE_CURRENT_USER, pCertContext, 0, hCertStore, (nint)(&amp;chainParams), chainFlags, 0, (nint)(&amp;pChainContext)).VerifyWinapiTrue(); } finally { if (pChainContext != 0) CertFreeCertificateChain(pChainContext); } <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041a\u0430\u043a \u044f \u0438 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u043b \u0440\u0430\u043d\u0435\u0435, \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442, \u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u043c\u0435\u043b\u043e\u0447\u0430\u0445. \u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u043a\u043b\u044e\u0447\u0430\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b P\/Invoke \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b <a href=\"https:\/\/github.com\/AntoineLarine\/NetWinapiCms\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>P.S.<\/h3>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/734368\/\"> https:\/\/habr.com\/ru\/articles\/734368\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u0441\u0432\u0435\u0436\u0435\u043c .NET 7 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432. \u0420\u0430\u043d\u0435\u0435, \u0432 .NET Framework  \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0413\u041e\u0421\u0422 (CryptoPro CSP, ViPNet CSP \u0438 \u043f\u0440.), \u0448\u043b\u0430 &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;. \u041f\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b \u043a\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.cryptography.pkcs.signedcms?view=dotnet-plat-ext-7.0\" rel=\"noopener noreferrer nofollow\"><code>SignedCms<\/code><\/a>, \u0438 voil\u00e0:<\/p>\n<pre><code>System.Security.Cryptography.CryptographicException: 'Could not determine signature algorithm for the signer certificate.' <\/code><\/pre>\n<p>\u042f\u0441\u043d\u043e-\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u043d\u043e\u0432\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043f\u043e\u043c\u043d\u043e\u0436\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u043d\u043e\u043b\u044c. <\/p>\n<h3>\u0427\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a?<\/h3>\n<p>\u041f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 .NET \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u044b\u0432\u0435\u043b\u0430 \u043d\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/26053\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0433, \u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u0443\u0436\u0435 \u043f\u044f\u0442\u044c \u043b\u0435\u0442<\/a>. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 .NET Team \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0413\u041e\u0421\u0422 \u0420 34.10-2012 \u0434\u0430\u0440\u043e\u043c \u043d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0431\u0438\u043b\u0438.<\/p>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/h3>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0431\u044b\u043b\u0430 &#171;\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0436\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0435\u043d\u0441\u043e\u0440\u0441, \u0437\u0430\u043f\u0438\u043b\u0438 \u0441\u0430\u043c&#187;. \u041d\u043e \u0432\u044b\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0451\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u043f\u0443\u0433\u043d\u0443\u043b \u0434\u0435\u043b\u0430\u0442\u044c &#171;\u0441 \u043a\u043e\u043b\u0451\u0441&#187;, \u0434\u0430 \u0438 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/docs\/project\/api-review-process.md\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c API Proposal<\/a> &#8212; \u0442\u043e\u0442 \u0435\u0449\u0451 \u043a\u0432\u0435\u0441\u0442.<\/p>\n<p>\u0418\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 <a href=\"https:\/\/github.com\/bcgit\/bc-csharp\" rel=\"noopener noreferrer nofollow\">Bouncy Castle<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u043f\u043e\u0441\u043b\u0435 <a href=\"https:\/\/github.com\/bcgit\/bc-csharp\/issues\/231\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0443\u0445\u043b\u0435\u0442\u043d\u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f<\/a> \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e PR \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u0434\u043b\u044f CMS, \u0442\u043e\u0436\u0435 \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043e\u0442\u043f\u0430\u043b, \u0442\u0430\u043a \u043a\u0430\u043a \u0441 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0436\u0435\u043b\u0430\u0435\u0442 (\u0438\u043b\u0438 \u044f \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b).<\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u0434\u0435\u0431\u0440\u044f\u0445 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u043c\u043e\u0439 \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0443\u0436\u0435 \u0432 \u0434\u0430\u043b\u0451\u043a\u043e\u043c 2015 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u043d\u0430 \u0433\u043e\u043b\u043e\u043c WinAPI. \u0410 \u0442\u0430\u043a \u043a\u0430\u043a P\/Invoke \u0438\u0437 .NET <em>\u043f\u043e\u043a\u0430<\/em> \u043d\u0435 \u0432\u044b\u043f\u0438\u043b\u0438\u043b\u0438, \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c, \u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0438 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u043e\u043c \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u044b \u0432\u0435\u0447\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0438\u043d\u0433\u0430, \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0448\u043b\u0430 \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u043e\u043b\u043e\u0447\u0435\u043a \u0434\u043b\u044f CryptoAPI.<\/p>\n<h3>\u0414\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 WinAPI<\/h3>\n<p>\u0412 WinAPI \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/seccrypto\/low-level-messages\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a> \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440. \u0412\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Microsoft, \u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0443\u043b\u044f \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u0438\u043b\u0438\u0439 \u0438 \u043e\u0431\u043e\u0439\u0442\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439. \u0414\u0430\u043b\u0435\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0443\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u042d\u041f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0434\u0430\u043b\u0435\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/AntoineLarine\/NetWinapiCms\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<p><strong>Disclaimer<\/strong>. \u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e unsafe-\u043a\u043e\u0434\u0430 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043d\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 C#, \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>Span&lt;T><\/code>. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0435 &#171;C# &#8212; \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u044f\u0437\u044b\u043a&#187; \u0438 \u0442.\u043f., \u043d\u043e \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0448\u043a\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0439 \u043b\u0438\u0448\u043d\u0438\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043a\u0443\u0447\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u043b\u0438\u043d\u0433\u0435.<\/p>\n<h4>\u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u043b\u0438\u0448\u043d\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptacquirecertificateprivatekey\" rel=\"noopener noreferrer nofollow\"><code>CryptAcquireCertificatePrivateKey<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentoencode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToEncode<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0432\u043b\u0435\u0447\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0438 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0430\u0439\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam<\/code><\/a>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0443\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0443:<\/p>\n<pre><code class=\"cs\">\/\/ acquire certificate private key var flags = (silent ? CRYPT_ACQUIRE_SILENT_FLAG : 0U) | CRYPT_ACQUIRE_COMPARE_KEY_FLAG; CryptAcquireCertificatePrivateKey(certificate.Handle, flags, 0, out var hProvider, out var dwKeySpec, out var pfCallerFreeProv).VerifyWinapiTrue(); try { ... } finally { if (pfCallerFreeProv) if (dwKeySpec == CERT_NCRYPT_KEY_SPEC) NCryptFreeObject(hProvider); else CryptReleaseContext(hProvider, 0); } <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptacquirecertificateprivatekey\" rel=\"noopener noreferrer nofollow\"><code>CryptAcquireCertificatePrivateKey<\/code><\/a> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0443, \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0438 \u0444\u043b\u0430\u0433 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0436\u0435\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 <code>try\/finally<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435, \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c \u043c\u0443\u0441\u043e\u0440\u0430 \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0438 \u0432\u0441\u0451 \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0430\u0439\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b-\u0445\u0435\u043b\u043f\u0435\u0440\u044b <code>VerifyWinapiTrue()<\/code> \u0438 <code>VerifyWinapiNonzero()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u0446\u0438\u0439 WinAPI \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>Win32Exception<\/code> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/errhandlingapi\/nf-errhandlingapi-getlasterror\" rel=\"noopener noreferrer nofollow\"><code>GetLastError<\/code><\/a>.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441 \u0432 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u0432\u044b\u0448\u0435 &#8212; \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u043b\u0430\u0433\u0430 <code>CRYPT_ACQUIRE_SILENT_FLAG<\/code>. \u041e\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u043e\u043a\u043e\u043d \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c&#187; \u0438\u043b\u0438 &#171;\u0432\u0432\u0435\u0434\u0438\u0442\u0435 PIN-\u043a\u043e\u0434 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430&#187;, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0438\u0437 \u0441\u043b\u0443\u0436\u0431\u044b. \u042d\u0442\u043e\u0442 \u0444\u043b\u0430\u0433 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043e\u043a\u043d\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u044c PIN-\u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043c\u043e\u0433 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">if (pin.Length > 0) { \/\/ set PIN-code for the private key var asciiPinLength = Encoding.ASCII.GetByteCount(pin); var asciiPin = stackalloc byte[asciiPinLength + 1]; Encoding.ASCII.GetBytes(pin, new Span&lt;byte>(asciiPin, asciiPinLength)); if (dwKeySpec == AT_KEYEXCHANGE) CryptSetProvParam(hProvider, PP_KEYEXCHANGE_PIN, (nint)asciiPin, 0).VerifyWinapiTrue(); else if (dwKeySpec == AT_SIGNATURE) CryptSetProvParam(hProvider, PP_SIGNATURE_PIN, (nint)asciiPin, 0).VerifyWinapiTrue(); } <\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e PIN-\u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0431\u0430\u0439\u0442\u043d\u043e\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 ASCII (\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0439 PIN?).<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432, \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u0435 \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">\/\/ acquiring certificate context var certContext = new ReadOnlySpan&lt;CERT_CONTEXT>(certificate.Handle.ToPointer(), 1); var signerCertBlob = new CRYPT_INTEGER_BLOB { cbData = certContext[0].cbCertEncoded, pbData = certContext[0].pbCertEncoded };  \/\/ prepare CMSG_SIGNER_ENCODE_INFO structure var signerInfo = new CMSG_SIGNER_ENCODE_INFO(); signerInfo.cbSize = (uint)Marshal.SizeOf(signerInfo); signerInfo.pCertInfo = certContext[0].pCertInfo; signerInfo.hKey = hProvider; signerInfo.dwKeySpec = dwKeySpec; signerInfo.HashAlgorithm.pszObjId = (nint)digestOidRaw;  \/\/ prepare CMSG_SIGNED_ENCODE_INFO structure var signedInfo = new CMSG_SIGNED_ENCODE_INFO(); signedInfo.cbSize = (uint)Marshal.SizeOf(signedInfo); signedInfo.cSigners = 1; signedInfo.rgSigners = (nint)(&amp;signerInfo); signedInfo.cCertEncoded = 1; signedInfo.rgCertEncoded = (nint)(&amp;signerCertBlob);  \/\/ create CMS var hMsg = CryptMsgOpenToEncode(MsgEncodingTypes.X509_ASN_ENCODING | MsgEncodingTypes.PKCS_7_ASN_ENCODING, detachedSignature ? CMSG_DETACHED_FLAG : 0U, MsgType.CMSG_SIGNED, (nint)(&amp;signedInfo), null, 0).VerifyWinapiNonzero(); try { ... } finally { CryptMsgClose(hMsg); } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0437\u044e\u043c\u0438\u043d\u043a\u0430 \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.cryptography.x509certificates.x509certificate.handle?view=net-7.0\" rel=\"noopener noreferrer nofollow\"><code>X509Certificate.Handle<\/code><\/a> \u0443\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u043d\u0430 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/ns-wincrypt-cert_context\" rel=\"noopener noreferrer nofollow\"><code>CERT_CONTEXT<\/code><\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043a \u0442\u0438\u043f\u0443 <code>ReadOnlySpan&lt;CERT_CONTEXT><\/code> \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u043c\u0430\u0440\u0448\u0430\u043b\u043b\u0438\u043d\u0433\u0430.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0444\u043b\u0430\u0433 <code>CMSG_DETACHED_FLAG<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentoencode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToEncode<\/code><\/a>. \u0415\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c, \u0442.\u0435. CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0441\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435 \u0441 \u043a\u0440\u0438\u043f\u0442\u043e\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f\u0432\u043d\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgclose\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgClose()<\/code><\/a>.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438. \u0412\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c:<\/p>\n<pre><code class=\"cs\">\/\/ add, hash, and sign the data fixed (byte* pData = data) CryptMsgUpdate(hMsg, (nint)pData, (uint)data.Length, true).VerifyWinapiTrue(); <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0438\u0437 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">\/\/ extract signed CMS var cmsLength = 0; CryptMsgGetParam(hMsg, CMSG_CONTENT_PARAM, 0, 0, ref cmsLength).VerifyWinapiTrue(); var cms = new byte[cmsLength]; fixed (byte* pSignature = cms) CryptMsgGetParam(hMsg, CMSG_CONTENT_PARAM, 0, (nint)pSignature, ref cmsLength).VerifyWinapiTrue(); <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u043e \u043a\u0430\u043d\u043e\u043d\u0443, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0434\u0432\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 CryptoAPI. \u041f\u0435\u0440\u0432\u044b\u0439 &#8212; \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 <code>cms<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <code>.sig<\/code>, \u0438 \u0432\u0441\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u041a\u0440\u0438\u043f\u0442\u043e-\u0410\u0420\u041c \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a &#171;\u043e\u0431\u044b\u0447\u043d\u0443\u044e&#187; \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c.<\/p>\n<h4>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438<\/h4>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WinAPI \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0435\u0451 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u0438\u0437-\u0437\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0438, \u043d\u0435 \u043f\u0440\u043e\u0449\u0435 \u043b\u0438 \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430?) \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc5652.html\" rel=\"noopener noreferrer nofollow\">PKCS #7<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0435\u0439 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/CAdES\" rel=\"noopener noreferrer nofollow\">CAdES<\/a>.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432), \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f \u0432 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438, \u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0442\u0430\u043c\u043f\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0418 \u0432\u043d\u043e\u0432\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043e\u0431\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 CMS-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgopentodecode\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgOpenToDecode<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgupdate\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgUpdate<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-certopenstore\" rel=\"noopener noreferrer nofollow\"><code>CertOpenStore<\/code><\/a> \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0432\u0441\u0435 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b, \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u0434\u043f\u0438\u0441\u044c. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam(..., CMSG_SIGNER_COUNT_PARAM, ...)<\/code><\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0435\u0439 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0442\u0430 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsggetparam\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgGetParam(..., CMSG_SIGNER_CERT_ID_PARAM, ...)<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 5, \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-certfindcertificateinstore\" rel=\"noopener noreferrer nofollow\"><code>CertFindCertificateInStore(..., CERT_FIND_CERT_ID, ...)<\/code><\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptmsgcontrol\" rel=\"noopener noreferrer nofollow\"><code>CryptMsgControl(...,<\/code><\/a><\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-405219","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=405219"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405219\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=405219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=405219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=405219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}