久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='jYJQC'></bdo><ul id='jYJQC'></ul>

    <legend id='jYJQC'><style id='jYJQC'><dir id='jYJQC'><q id='jYJQC'></q></dir></style></legend>

      <small id='jYJQC'></small><noframes id='jYJQC'>

    1. <i id='jYJQC'><tr id='jYJQC'><dt id='jYJQC'><q id='jYJQC'><span id='jYJQC'><b id='jYJQC'><form id='jYJQC'><ins id='jYJQC'></ins><ul id='jYJQC'></ul><sub id='jYJQC'></sub></form><legend id='jYJQC'></legend><bdo id='jYJQC'><pre id='jYJQC'><center id='jYJQC'></center></pre></bdo></b><th id='jYJQC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jYJQC'><tfoot id='jYJQC'></tfoot><dl id='jYJQC'><fieldset id='jYJQC'></fieldset></dl></div>

    2. <tfoot id='jYJQC'></tfoot>
    3. C# 從文本文件中的公鑰獲取 CngKey 對象

      C# Get CngKey object from public key in text file(C# 從文本文件中的公鑰獲取 CngKey 對象)
    4. <small id='BKcbu'></small><noframes id='BKcbu'>

            <legend id='BKcbu'><style id='BKcbu'><dir id='BKcbu'><q id='BKcbu'></q></dir></style></legend>
          1. <tfoot id='BKcbu'></tfoot>
              <bdo id='BKcbu'></bdo><ul id='BKcbu'></ul>

              • <i id='BKcbu'><tr id='BKcbu'><dt id='BKcbu'><q id='BKcbu'><span id='BKcbu'><b id='BKcbu'><form id='BKcbu'><ins id='BKcbu'></ins><ul id='BKcbu'></ul><sub id='BKcbu'></sub></form><legend id='BKcbu'></legend><bdo id='BKcbu'><pre id='BKcbu'><center id='BKcbu'></center></pre></bdo></b><th id='BKcbu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BKcbu'><tfoot id='BKcbu'></tfoot><dl id='BKcbu'><fieldset id='BKcbu'></fieldset></dl></div>
                  <tbody id='BKcbu'></tbody>

                本文介紹了C# 從文本文件中的公鑰獲取 CngKey 對象的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我有一個文件,其中有幾個 ECDSA SHA256 的公鑰.該文件如下所示:

                I have got a file in which there are several public keys for ECDSA SHA256. The file looks like:

                KEY_ID: 1
                STATUS: VALID
                -----BEGIN PUBLIC KEY-----
                MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaq6djyzkpHdX7kt8DsSt6IuSoXjp
                WVlLfnZPoLaGKc/2BSfYQuFIO2hfgueQINJN3ZdujYXfUJ7Who+XkcJqHQ==
                -----END PUBLIC KEY-----
                
                KEY_ID: 2
                STATUS: VALID
                -----BEGIN PUBLIC KEY-----
                MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+Y5mYZL/EEY9zGji+hrgGkeoyccK
                D0/oBoSDALHc9+LXHKsxXiEV7/h6d6+fKRDb6Wtx5cMzXT9HyY+TjPeuTg==
                -----END PUBLIC KEY-----
                
                KEY_ID: 3
                STATUS: VALID
                -----BEGIN PUBLIC KEY-----
                MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkvgJ6sc2MM0AAFUJbVOD/i34YJJ8
                ineqTN+DMjpI5q7fQNPEv9y2z/ecPl8qPus8flS4iLOOxdwGoF1mU9lwfA==
                -----END PUBLIC KEY-----
                

                我怎樣才能為這些鍵中的一個(或全部)獲取 CngKey 對象(或 CngKey 列表)?

                How can I can get CngKey object (or list of CngKey) for one (or all) of these keys?

                我嘗試過類似的東西

                string plainTextKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaq6djyzkpHdX7kt8DsSt6IuSoXjpWVlLfnZPoLaGKc/2BSfYQuFIO2hfgueQINJN3ZdujYXfUJ7Who+XkcJqHQ==";
                byte[] publicKeyBytes = Convert.FromBase64String(plainTextKey);
                CngKey ret = CngKey.Import(publicKeyBytes, CngKeyBlobFormat.EccPublicBlob);
                

                但是 Import 方法拋出 System.Security.Cryptography.CryptographicException 無效參數.

                but Import method throws System.Security.Cryptography.CryptographicException for invalid parameter.

                推薦答案

                EccPublicBlob 映射到 BCRYPT_ECCPUBLIC_BLOB 格式類型,不是 X.509 SubjectPublicKeyInfo.

                EccPublicBlob maps to BCRYPT_ECCPUBLIC_BLOB format type, not X.509 SubjectPublicKeyInfo.

                如果您的所有密鑰都在 secp256r1/NIST P-256 上,那么有一個非常簡單的 hacky 方法.

                If all of your keys are on secp256r1/NIST P-256 then there's a pretty straightforward hacky approach.

                您可能已經注意到,您的所有密鑰都以 MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE 開頭.我們很快就會看到原因.

                You may have noticed that all of your keys start with MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE. We'll see why shortly.

                轉換

                MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaq6djyzkpHdX7kt8DsSt6IuSoXjp
                WVlLfnZPoLaGKc/2BSfYQuFIO2hfgueQINJN3ZdujYXfUJ7Who+XkcJqHQ==
                

                到字節(或者,這里是十六進制):

                to bytes (or, here, hex):

                30 59 30 13 06 07 2A 86 48 CE 3D 02 01 06 08 2A 
                86 48 CE 3D 03 01 07 03 42 00 04 6A AE 9D 8F 2C 
                E4 A4 77 57 EE 4B 7C 0E C4 AD E8 8B 92 A1 78 E9 
                59 59 4B 7E 76 4F A0 B6 86 29 CF F6 05 27 D8 42 
                E1 48 3B 68 5F 82 E7 90 20 D2 4D DD 97 6E 8D 85 
                DF 50 9E D6 86 8F 97 91 C2 6A 1D
                

                這是一個 DER 編碼的 X.509 SubjectPublicKeyInfo blob.

                This is a DER encoded X.509 SubjectPublicKeyInfo blob.

                使用我們看到的 DER-fu

                Using our DER-fu we see

                // SubjectPublicKeyInfo
                30 59  // SEQUENCE, 0x59 == 89 bytes of payload
                   // AlgorithmIdentifier
                   30 13  // SEQUENCE, 0x13 == 19 bytes of payload
                      // AlgorithmIdentifier.algorithm
                      06 07 2A 86 48 CE 3D 02 01  // OBJECT ID 1.2.840.10045.2.1 (id-ecPublicKey)
                      // AlgorithmIdentifier.parameters
                      06 08 2A 86 48 CE 3D 03 01 07 // OBJECT ID 1.2.840.10045.3.1.7 (secp256r1)
                   // SubjectPublicKeyInfo.publicKey
                   03 42 00  // BIT STRING, 0x42 == 66 (65) payload bytes, 0 unused bits
                      // "the public key"
                      04
                      92F809EAC73630CD000055096D5383FE2DF860927C8A77AA4CDF83323A48E6AE
                      DF40D3C4BFDCB6CFF79C3E5F2A3EEB3C7E54B888B38EC5DC06A05D6653D9707C
                

                由于算法標識符是 id-ecPublicKey,因此參數是標識曲線的 OID(在本例中為 secp256r1/NIST P-256).和公鑰"格式來自 SEC 1 v2.0 (2.3.4 Octet-String-到橢圓曲線點轉換).

                Since the algorithm identifier is id-ecPublicKey the parameters is an OID identifying the curve (in this case, secp256r1 / NIST P-256). And "the public key" is of a format from SEC 1 v2.0 (2.3.4 Octet-String-to-Elliptic-Curve-Point Conversion).

                最常見的編碼是類型04,未壓縮的密鑰.(0x04 后跟 Qx 填充到必要的長度,然后 Qy 填充到必要的長度).

                The most common encoding is type 04, uncompressed key. (0x04 followed by Qx padded to the necessary length followed by Qy padded to the necessary length).

                因此,對于在 secp256r1 上以 04 類型編碼的所有點,字節模式都以

                So, for all points encoded with type 04 on secp256r1 the byte pattern starts with

                30 59 30 13 06 07 2A 86 48 CE 3D 02 01 06 08 2A 
                86 48 CE 3D 03 01 07 03 42 00 04
                

                恰好與 MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE 的通用 base64 前綴對齊.

                which happens to align to a common base64 prefix of MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE.

                CNG 想要什么 是 [32 位標識符][32 位小端長度][填充 Qx][填充 Qy].

                What CNG wants is [32-bit identifier][32-bit little-endian length][padded Qx][padded Qy].

                所以超級騙子的hacky版本是:

                So the super-duper hacky version is:

                private static readonly byte[] s_secp256r1Prefix =
                    Convert.FromBase64String("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE");
                
                // For ECDH instead of ECDSA, change 0x53 to 0x4B.
                private static readonly byte[] s_cngBlobPrefix = { 0x45, 0x43, 0x53, 0x31, 0x20, 0, 0, 0 };
                
                private static CngKey ImportECDsa256PublicKey(string base64)
                {
                    byte[] subjectPublicKeyInfo = Convert.FromBase64String(base64);
                
                    if (subjectPublicKeyInfo.Length != 91)
                        throw new InvalidOperationException();
                
                    byte[] prefix = s_secp256r1Prefix;
                
                    if (!subjectPublicKeyInfo.Take(prefix.Length).SequenceEqual(prefix))
                        throw new InvalidOperationException();
                
                    byte[] cngBlob = new byte[s_cngBlobPrefix.Length + 64];
                    Buffer.BlockCopy(s_cngBlobPrefix, 0, cngBlob, 0, s_cngBlobPrefix.Length);
                
                    Buffer.BlockCopy(
                        subjectPublicKeyInfo,
                        s_secp256r1Prefix.Length,
                        cngBlob,
                        s_cngBlobPrefix.Length,
                        64);
                
                    return CngKey.Import(cngBlob, CngKeyBlobFormat.EccPublicBlob);
                }
                

                要支持其他曲線,您需要將 CNG blob 的前 4 個字節更改為正確的Magic";值,并將第 5 個字節更改為正確的長度.當然,不同的 SubjectPublicKeyInfo 前綴,64 不會是公鑰坐標長度(64 == 256/8 * 2).但所有這些都留給讀者作為練習.

                To support other curves you need to change the first 4 bytes of the CNG blob to the correct "Magic" value, and change the 5th byte to be the correct length. And, of course, different SubjectPublicKeyInfo prefixes, and 64 won't be the public key coordinate length (64 == 256 / 8 * 2). But all of that is left as an exercise to the reader.

                請參閱 C# 和 PHP ECDH 不匹配反過來.

                這篇關于C# 從文本文件中的公鑰獲取 CngKey 對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                onClick event for Image in Unity(Unity中圖像的onClick事件)
                Running Total C#(運行總 C#)
                Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                Calling A Button OnClick from a function(從函數調用按鈕 OnClick)

                • <tfoot id='oHsyg'></tfoot>
                  <legend id='oHsyg'><style id='oHsyg'><dir id='oHsyg'><q id='oHsyg'></q></dir></style></legend>
                      <tbody id='oHsyg'></tbody>
                  • <i id='oHsyg'><tr id='oHsyg'><dt id='oHsyg'><q id='oHsyg'><span id='oHsyg'><b id='oHsyg'><form id='oHsyg'><ins id='oHsyg'></ins><ul id='oHsyg'></ul><sub id='oHsyg'></sub></form><legend id='oHsyg'></legend><bdo id='oHsyg'><pre id='oHsyg'><center id='oHsyg'></center></pre></bdo></b><th id='oHsyg'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oHsyg'><tfoot id='oHsyg'></tfoot><dl id='oHsyg'><fieldset id='oHsyg'></fieldset></dl></div>

                    <small id='oHsyg'></small><noframes id='oHsyg'>

                      • <bdo id='oHsyg'></bdo><ul id='oHsyg'></ul>

                          主站蜘蛛池模板: 国产一区二区三区久久久久久久久 | 久久九九免费 | 免费欧美 | 精品久久久久久久久久久久 | 精品一区在线 | 欧美日日 | 久久精品国产一区老色匹 | 国产精品久久久久久久午夜 | 成人免费在线观看视频 | 尤物在线精品视频 | 日韩欧美国产一区二区三区 | h视频免费观看 | 九九九久久国产免费 | 国产成人精品免高潮在线观看 | 精品久久久久久亚洲精品 | 一区日韩 | 福利视频一区二区三区 | 成人午夜电影网 | 国产精品福利视频 | 国产高清视频在线 | 成人日韩精品 | 黄色大片网站 | 免费在线观看一区二区 | 国产一区2区| 日日操视频 | 国产yw851.c免费观看网站 | 免费黄色网址视频 | 亚洲国产高清在线观看 | 91精品国产自产精品男人的天堂 | 色资源在线观看 | 国产精品永久在线观看 | 日本人做爰大片免费观看一老师 | 国产亚洲一区二区精品 | 国产免费一区二区 | 婷婷成人在线 | 国产成人精品一区二区三区四区 | 激情国产| 91精品国产91久久久久游泳池 | 国产精品久久久久久福利一牛影视 | 日韩一区二区在线播放 | 日日夜精品视频 |