{"id":273318,"date":"2016-02-01T12:12:03","date_gmt":"2016-02-01T09:12:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273318"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273318","title":{"rendered":"\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0415\u0421\u0418\u0410 OAuth2"},"content":{"rendered":"<p>       \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u043a\u0430\u043a \u044f \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043b \u0415\u0421\u0418\u0410 \u043a \u0441\u0430\u0439\u0442\u0443, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 pfx \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u0435\u043c.<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u00abPFX Certificate Generator\u00bb. \u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: sha256, \u0434\u043b\u0438\u043d\u0430 \u043a\u043b\u044e\u0447\u0430 2048.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u0430\u0441\u0442\u043a\u0443 \u0434\u043b\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432. \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0442\u043a\u0443 \u00ab\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u00bb, \u043f\u043e\u0442\u043e\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u0443\u0434\u0430 \u043d\u0430\u0448 \u0441\u0433\u0435\u043d\u0435\u0440\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u041f\u043e\u0442\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0432\u0435\u0442\u043a\u0443 \u00ab\u0414\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0435\u00bb.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412 \u0432\u0435\u0442\u043a\u0435 \u00ab\u041b\u0438\u0447\u043d\u044b\u0435\u00bb \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u0448 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043a\u043b\u0438\u043a\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043c\u044b\u0448\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u00ab\u0412\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438\u00bb \u043f\u043e\u0442\u043e\u043c \u00ab\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438\u00bb. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0443 \u00ab\u0412\u0441\u0435\u00bb.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 cer \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0415\u0421\u0418\u0410, \u0442\u0430\u043c \u0435\u0433\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430. \u0423 \u0441\u0435\u0431\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b NancyFx. \u0418\u0442\u0430\u043a\u2026<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"cs\">        static string client_id = &quot;123456&quot;; \/\/\u041c\u043d\u0435\u043c\u043e\u043d\u0438\u043a\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0443 \u0415\u0421\u0418\u0410         static string state = Guid.NewGuid().ToString(&quot;D&quot;); \/\/\u0433\u0443\u0438\u0434 \u0434\u043b\u044f \u0432\u0441\u044f\u043a\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a         static string server_url = &quot;https:\/\/esia.gosuslugi.ru\/aas\/oauth2\/ac&quot;; \/\/\u0430\u0434\u0440\u0435\u0441\u0441 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0435\u0441\u0438\u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434         static string server_url_2 = &quot;https:\/\/esia.gosuslugi.ru\/aas\/oauth2\/te&quot;; \/\/\u0430\u0434\u0440\u0435\u0441\u0441 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u0430\u0440\u043a\u0435\u0440         static string server_url_prns = &quot;https:\/\/esia.gosuslugi.ru\/rs\/prns\/&quot;; \/\/\u0442\u0443\u0442 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u0424\u0418\u041e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a \u043d\u0430\u043c \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c\u0441\u044f  \/\/\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438        \/* static string server_url = &quot;https:\/\/esia-portal1.test.gosuslugi.ru\/aas\/oauth2\/ac&quot;;         static string server_url_2 = &quot;https:\/\/esia-portal1.test.gosuslugi.ru\/aas\/oauth2\/te&quot;;         static string server_url_prns = &quot;https:\/\/esia-portal1.test.gosuslugi.ru\/rs\/prns\/&quot;;*\/         public EsiaModule()         {             Get[&quot;\/ESIA&quot;] = _ =&gt;             {                  \/\/string scope = &quot;openid&quot;;                 string scope = &quot;fullname&quot;;                 string timestamp = DateTime.UtcNow.ToString(&quot;yyyy.MM.dd HH:mm:ss +0000&quot;);                 string access_type = &quot;online&quot;;                 string response_type = &quot;code&quot;;                 string redirect_uri = Request.Url.Scheme + &quot;:\/\/&quot; + Request.Url.HostName + (Request.Url.Port == 80 ? &quot;&quot; : (&quot;:&quot; + Request.Url.Port.ToString())) + &quot;\/ESIA-OK&quot;;  \/\/\u0430\u0434\u0440\u0435\u0441\u0441 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0430, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u0435\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0435\u0441\u0438\u0430                 string client_secret = &quot;&quot;;                 \/\/\u0413\u0435\u043d\u0435\u0440\u0438\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430                 string msg = scope + timestamp + client_id + state;                 byte[] msgBytes = Encoding.UTF8.GetBytes(msg);                 var signerCert = DetachedSignature.GetSignerCert();                 byte[] encodedSignature = DetachedSignature.SignMsg(msgBytes, signerCert);                 client_secret = HttpServerUtility.UrlTokenEncode(encodedSignature);                \/\/\u0433\u0435\u043d\u0435\u0440\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438                 RequestBuilder builder = new RequestBuilder();                 builder.AddParam(&quot;client_id&quot;, client_id);                 builder.AddParam(&quot;client_secret&quot;, client_secret);                 builder.AddParam(&quot;redirect_uri&quot;, redirect_uri);                 builder.AddParam(&quot;scope&quot;, scope);                 builder.AddParam(&quot;response_type&quot;, response_type);                 builder.AddParam(&quot;state&quot;, state);                 builder.AddParam(&quot;timestamp&quot;, timestamp);                 builder.AddParam(&quot;access_type&quot;, access_type);                  string red_url = server_url + &quot;?&quot; + builder.ToString().Replace(&quot;+&quot;, &quot;%2b&quot;);                 return Response.AsRedirect(red_url);             };             Get[&quot;\/ESIA-OK&quot;] = _ =&gt;             {                 \/\/\u0441\u044e\u0434\u0430 \u043d\u0430\u0441 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0442 \u0435\u0441\u0438\u0430, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c state \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u043e\u0441\u043b\u0430\u043d \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0448\u0435\u043b, \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c code                 string state_r = Request.Query[&quot;state&quot;];                 string code = Request.Query[&quot;code&quot;];                  if (state == state_r)                 {                     \/\/string scope = &quot;openid&quot;;                     string scope = &quot;fullname&quot;;                     string timestamp = DateTime.UtcNow.ToString(&quot;yyyy.MM.dd HH:mm:ss +0000&quot;);                     string redirect_uri = Request.Url.Scheme + &quot;:\/\/&quot; + Request.Url.HostName + (Request.Url.Port == 80 ? &quot;&quot; : (&quot;:&quot; + Request.Url.Port.ToString())) + &quot;\/ESIA-OK&quot;;                     string client_secret = &quot;&quot;;                     string msg = scope + timestamp + client_id + state;                     byte[] msgBytes = Encoding.UTF8.GetBytes(msg);                     var signerCert = DetachedSignature.GetSignerCert();                     byte[] encodedSignature = DetachedSignature.SignMsg(msgBytes, signerCert);                     client_secret = HttpServerUtility.UrlTokenEncode(encodedSignature);                      string result;                     \/\/\u0433\u0435\u043d\u0435\u0440\u0438\u043c post \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0440\u043a\u0435\u0440\u0430                     {                         RequestBuilder builder = new RequestBuilder();                         builder.AddParam(&quot;client_id&quot;, client_id);                         builder.AddParam(&quot;code&quot;, code);                         builder.AddParam(&quot;grant_type&quot;, &quot;authorization_code&quot;);                         builder.AddParam(&quot;client_secret&quot;, client_secret);                         builder.AddParam(&quot;state&quot;, state);                         builder.AddParam(&quot;redirect_uri&quot;, redirect_uri);                         builder.AddParam(&quot;scope&quot;, scope);                         builder.AddParam(&quot;timestamp&quot;, timestamp);                         builder.AddParam(&quot;token_type&quot;, &quot;Bearer&quot;);                          var httpWebRequest = (HttpWebRequest)WebRequest.Create(server_url_2);                         httpWebRequest.ContentType = &quot;application\/x-www-form-urlencoded&quot;;                         httpWebRequest.Method = &quot;POST&quot;;                         httpWebRequest.Timeout = int.MaxValue;                              WebProxy p = new WebProxy();                         p.Address = new Uri(&quot;http:\/\/192.168.2.5:8080&quot;);                         p.Credentials = new NetworkCredential(@&quot;vrn\\ituprtrans&quot;, &quot;2015Avtobus&quot;);                         httpWebRequest.Proxy = p;                         using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))                         {                             streamWriter.Write(builder.ToString().Replace(&quot;+&quot;, &quot;%2b&quot;));                             streamWriter.Flush();                             streamWriter.Close();                         }                          var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();                         using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))                         {                             result = streamReader.ReadToEnd();                         }                     }                     ESIA_Marker_Answer marker = JsonConvert.DeserializeObject&lt;ESIA_Marker_Answer&gt;(result);\/\/\u043d\u0430\u0448 \u043c\u0430\u0440\u043a\u0435\u0440                      string[] marker_parts = marker.access_token.Split('.');                      string header = Encoding.UTF8.GetString(base64urldecode(marker_parts[0]));                     string payload = Encoding.UTF8.GetString(base64urldecode(marker_parts[1]));                     string oid = (JsonConvert.DeserializeObject&lt;dynamic&gt;(payload))[&quot;urn:esia:sbj_id&quot;];                      \/\/\u0433\u0435\u043d\u0435\u0440\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435                     string user_info = &quot;&quot;;                     {                         var httpWebRequest = (HttpWebRequest)WebRequest.Create(server_url_prns + oid);                         httpWebRequest.ContentType = &quot;application\/x-www-form-urlencoded&quot;;                         httpWebRequest.Method = &quot;GET&quot;;                         httpWebRequest.Headers[&quot;Authorization&quot;] = &quot;Bearer &quot; + marker.access_token;                         httpWebRequest.Timeout = int.MaxValue;                         WebProxy p = new WebProxy();                         p.Address = new Uri(&quot;http:\/\/127.0.0.1:8080&quot;); \/\/\u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438                         p.Credentials = new NetworkCredential(@&quot;vrn\\ituprtrans&quot;, &quot;2015Avtobus&quot;);                         httpWebRequest.Proxy = p;                          var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();                         using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))                         {                             user_info = streamReader.ReadToEnd();                         }                     }                      string firstName = JsonConvert.DeserializeObject&lt;dynamic&gt;(user_info)[&quot;firstName&quot;];                     string lastName = &quot;&quot;;                     try                     {                         lastName = JsonConvert.DeserializeObject&lt;dynamic&gt;(user_info)[&quot;lastName&quot;];                     }                     catch { }                     string middleName = &quot;&quot;;                     try                     {                         middleName = JsonConvert.DeserializeObject&lt;dynamic&gt;(user_info)[&quot;middleName&quot;];                     }                     catch { }                       \/\/ \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432 \u0431\u0434 \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0430\u043d \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0435\u0441\u043b\u0438 \u0437\u0430\u0440\u0435\u0433\u0430\u043d                      MyEntities db = new MyEntities();                     Helper h = new Helper();                     users u;                     if (db.users.Any(a =&gt; a.esia_oid.Trim() == oid.Trim()))                     {                         u = db.users.FirstOrDefault(a =&gt; a.esia_oid.Trim() == oid.Trim());                     }                     else                     {                         \/\/create user                                                 u = new users                         {                             mail = oid,                             name = firstName,                             pass = h.HashWithSalt(oid),                             patronymic = middleName ?? &quot;&quot;,                             surname = lastName ?? &quot;&quot;,                             token = Guid.NewGuid().ToString(&quot;N&quot;),                             role_id = 2,                             esia_oid = oid                         };                         db.users.Add(u);                         db.SaveChanges();                     }                     \/\/\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043a\u0443\u043a\u0438 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e                     DateTime expires = DateTime.UtcNow.AddYears(20);                     List&lt;NancyCookie&gt; cs = new List&lt;NancyCookie&gt; { new NancyCookie(&quot;id&quot;, u.id.ToString(), false) { Expires = expires }, new NancyCookie(&quot;token&quot;, u.token, false) { Expires = expires } };                     var resp = Response.AsRedirect(&quot;\/&quot;);                     resp.AddCookie(cs[0]);                     resp.AddCookie(cs[1]);                      return resp;                 }                 else                 {                     return Response.AsJson(new { err = 1 });                 }             };         }         static byte[] base64urldecode(string arg)         {             string s = arg;             s = s.Replace('-', '+'); \/\/ 62nd char of encoding             s = s.Replace('_', '\/'); \/\/ 63rd char of encoding             switch (s.Length % 4) \/\/ Pad with trailing '='s             {                 case 0: break; \/\/ No pad chars in this case                 case 2: s += &quot;==&quot;; break; \/\/ Two pad chars                 case 3: s += &quot;=&quot;; break; \/\/ One pad char                 default: throw new System.Exception(                   &quot;Illegal base64url string!&quot;);             }             return Convert.FromBase64String(s); \/\/ Standard base64 decoder         }     }      public class RequestBuilder     {         List&lt;RequesItemClass&gt; items = new List&lt;RequesItemClass&gt;();         public void AddParam(string name, string value)         {             items.Add(new RequesItemClass { name = name, value = value });         }         override public string ToString()         {             return string.Join(&quot;&&quot;, items.Select(a =&gt; a.name + &quot;=&quot; + a.value));         }     }      class DetachedSignature     {              static public X509Certificate2 GetSignerCert()         {                         X509Store storeMy = new X509Store(StoreName.My, StoreLocation.LocalMachine);             storeMy.Open(OpenFlags.ReadOnly);             X509Certificate2Collection certColl = storeMy.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, &quot;12 34 56 78 90 00 00 00 11 11 11 11 11 11 11 11 11 22 33 44&quot;, false);             storeMy.Close();             return certColl[0];         }                 static public byte[] SignMsg(Byte[] msg, X509Certificate2 signerCert)         {             ContentInfo contentInfo = new ContentInfo(msg);             SignedCms signedCms = new SignedCms(contentInfo, true);             CmsSigner cmsSigner = new CmsSigner(signerCert);             signedCms.ComputeSignature(cmsSigner);             return signedCms.Encode();         }          static public bool VerifyMsg(Byte[] msg, byte[] encodedSignature)         {             ContentInfo contentInfo = new ContentInfo(msg);             SignedCms signedCms = new SignedCms(contentInfo, true);             signedCms.Decode(encodedSignature);              try             {                 signedCms.CheckSignature(true);                           }             catch (System.Security.Cryptography.CryptographicException e)             {                 return false;             }              return true;         }     }      public class ESIA_Marker_Answer     {         public string state { get; set; }         public string token_type { get; set; }         public int expires_in { get; set; }         public string refresh_token { get; set; }         public string id_token { get; set; }         public string access_token { get; set; }     } <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0438 \u0432\u0441\u0435. \u041e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 + 2 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0440\u043a\u0435\u0440\u0430 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. <br \/>  \u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u043c\u0430\u0440\u043a\u0435\u0440\u0430.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \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:\/\/habrahabr.ru\/post\/276313\/\"> https:\/\/habrahabr.ru\/post\/276313\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u043a\u0430\u043a \u044f \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043b \u0415\u0421\u0418\u0410 \u043a \u0441\u0430\u0439\u0442\u0443, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 pfx \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u0435\u043c.<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u00abPFX Certificate Generator\u00bb. \u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: sha256, \u0434\u043b\u0438\u043d\u0430 \u043a\u043b\u044e\u0447\u0430 2048.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u0430\u0441\u0442\u043a\u0443 \u0434\u043b\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432. \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0442\u043a\u0443 \u00ab\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u00bb, \u043f\u043e\u0442\u043e\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u0443\u0434\u0430 \u043d\u0430\u0448 \u0441\u0433\u0435\u043d\u0435\u0440\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u041f\u043e\u0442\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0432\u0435\u0442\u043a\u0443 \u00ab\u0414\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0435\u00bb.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412 \u0432\u0435\u0442\u043a\u0435 \u00ab\u041b\u0438\u0447\u043d\u044b\u0435\u00bb \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u0448 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043a\u043b\u0438\u043a\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043c\u044b\u0448\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u00ab\u0412\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438\u00bb \u043f\u043e\u0442\u043e\u043c \u00ab\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438\u00bb. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0443 \u00ab\u0412\u0441\u0435\u00bb.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 cer \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0415\u0421\u0418\u0410, \u0442\u0430\u043c \u0435\u0433\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430. \u0423 \u0441\u0435\u0431\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b NancyFx. \u0418\u0442\u0430\u043a\u2026  <\/p>\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-273318","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273318","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=273318"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273318\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}