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

<small id='7COKO'></small><noframes id='7COKO'>

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

<legend id='7COKO'><style id='7COKO'><dir id='7COKO'><q id='7COKO'></q></dir></style></legend>

  1. <tfoot id='7COKO'></tfoot>

        <bdo id='7COKO'></bdo><ul id='7COKO'></ul>

      導入 RSA CngKey 并存儲在 MicrosoftSoftwareKeyStoragePro

      Import RSA CngKey and store in MicrosoftSoftwareKeyStorageProvider(導入 RSA CngKey 并存儲在 MicrosoftSoftwareKeyStorageProvider 中)
        <tbody id='3Dec6'></tbody>

          • <bdo id='3Dec6'></bdo><ul id='3Dec6'></ul>
            <legend id='3Dec6'><style id='3Dec6'><dir id='3Dec6'><q id='3Dec6'></q></dir></style></legend>
            <tfoot id='3Dec6'></tfoot>

                <small id='3Dec6'></small><noframes id='3Dec6'>

                <i id='3Dec6'><tr id='3Dec6'><dt id='3Dec6'><q id='3Dec6'><span id='3Dec6'><b id='3Dec6'><form id='3Dec6'><ins id='3Dec6'></ins><ul id='3Dec6'></ul><sub id='3Dec6'></sub></form><legend id='3Dec6'></legend><bdo id='3Dec6'><pre id='3Dec6'><center id='3Dec6'></center></pre></bdo></b><th id='3Dec6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3Dec6'><tfoot id='3Dec6'></tfoot><dl id='3Dec6'><fieldset id='3Dec6'></fieldset></dl></div>
                本文介紹了導入 RSA CngKey 并存儲在 MicrosoftSoftwareKeyStorageProvider 中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我有一個導出的 RSAParameters 私鑰,我想將它導入另一臺機器.我可以將 new 密鑰保存到本地計算機或用戶容器中,但我無法嘗試導入 現有 密鑰.

                I have an exported RSAParameters private key that I'd like to import into another machine. I can save new keys into the local machine or user containers, but I'm stuck trying to import an existing key.

                下面的代碼將生成一個新的密鑰對,我知道我可以直接在容器中生成一個新密鑰 - 但我希望能夠生成一個密鑰并將同一個密鑰導入到少數不同的計算機中.

                The code below will generate a new key pair, and I know I could just generate a new key directly into the container - but I want to be able to generate a single key and import that same key into a handful of different computers.

                如何獲取 RSAParameters 或 XML 字符串(任一)并將其導入本地用戶(或機器)容器?

                How can I take either an RSAParameters or a string of XML (either one) and import that into a local user (or machine) container?

                    public async Task<KeyGenerationResult> GenerateNewKeyAsync(int keySize)
                    {
                        var csp = new RSACng(keySize);
                
                        var privKey = await Task.Run(() => csp.ExportParameters(includePrivateParameters: true));
                        var pubKey = csp.ExportParameters(includePrivateParameters: false);
                
                        var pubKeyString = exportKeyToString(pubKey);
                        var privKeyString = exportKeyToString(privKey);
                
                        return new KeyGenerationResult
                        {
                            PrivateKey = privKey,
                            PublicKey = pubKey,
                            PrivateKeyCleartext = privKeyString,
                            PublicKeyCleartext = pubKeyString
                        };
                    }
                
                    private static string exportKeyToString(RSAParameters key)
                    {
                        string keyString;
                        var sw = new StringWriter();
                        var xs = new XmlSerializer(typeof(RSAParameters));
                        xs.Serialize(sw, key);
                        keyString = sw.ToString();
                        return keyString;
                    }
                
                    public void SavePrivateKeyToLocalMachine(RSAParameters privateKey, string keyName)
                    {
                       //Stuck here. :(
                    }
                

                CngKey.Import() 需要一個字節[],這看起來很有希望,但我無法找到任何方法來創建 CngKey.Import() 所需的字節[].

                CngKey.Import() takes a byte[] and that looks promising, but I haven't been able to find any method to create the byte[] that CngKey.Import() requires.

                        var d = new RSACryptoServiceProvider();
                        d.ImportParameters(privateKey);
                        var keyBlob = d.ExportCspBlob(true);
                        var key = CngKey.Import(keyBlob, CngKeyBlobFormat.Pkcs8PrivateBlob);
                

                這給了我一個字節[],但無論我使用什么 CngKeyBlobFormat,我都會遇到異常.我被卡住了.

                That gets me a byte[] but regardless of what CngKeyBlobFormat I use, I get an exception. I'm stuck.

                更新

                我找到了一種使用

                 var cp = new CngKeyCreationParameters();
                 cp.KeyUsage = CngKeyUsages.AllUsages;
                 cp.ExportPolicy = CngExportPolicies.AllowPlaintextExport | CngExportPolicies.AllowExport | CngExportPolicies.AllowArchiving | CngExportPolicies.AllowPlaintextArchiving;
                 cp.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(keySize), CngPropertyOptions.None));
                 var key = CngKey.Create(CngAlgorithm.Rsa, null, cp);
                 var bytes = key.Export(CngKeyBlobFormat.{I have tried them all});
                

                這段代碼看起來像它應該讓我導入字節[]

                And this code looks like it should let me import the byte[]

                 /* try to save this key to the local user container */
                 var keyParameters = new CngKeyCreationParameters()
                 {
                     KeyCreationOptions = CngKeyCreationOptions.OverwriteExistingKey,
                     Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider,
                     KeyUsage = CngKeyUsages.AllUsages,
                     ExportPolicy = CngExportPolicies.AllowPlaintextExport
                 };
                 keyParameters.KeyCreationOptions = CngKeyCreationOptions.None;
                 keyParameters.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(keySize), CngPropertyOptions.None));
                 keyParameters.Parameters.Add(new CngProperty(blobType.Format, bytes, CngPropertyOptions.None));
                
                 var newKey = CngKey.Create(CngAlgorithm.Rsa, "MyTestName", keyParameters);
                

                ...但再一次,沒有骰子.我嘗試什么 CngKeyBlobFormat 都沒關系,它們都給了我例外,我無法將密鑰導入本地密鑰存儲提供程序.

                ...but once again, no dice. It doesn't matter what CngKeyBlobFormat I try, they all give me exceptions and I'm unable to import the key into a local key storage provider.

                我需要什么神奇的設置和參數組合才能完成這項工作?

                What magic mix of settings and parameters do I need to make this work?

                推薦答案

                好吧,我終于搞定了.這是最終穩定下來的代碼.

                Well, I finally got it working. Here's the code as it finally settled down.

                public class KeyGenerationResult
                {
                    public RSAParameters PublicKey { get; set; }
                    public string PublicKeyCleartext { get; set; }
                    public string PrivateKeyCleartext { get; set; }
                    public byte[] PrivateBytes { get; set; }
                    public int KeySize { get; set; }
                    public CngKeyBlobFormat BlobFormat { get; set; }
                }
                
                    public async Task<KeyGenerationResult> GenerateNewKeyAsync(int keySize)
                    {
                        var cp = new CngKeyCreationParameters();
                        cp.KeyUsage = CngKeyUsages.AllUsages;
                        cp.ExportPolicy = CngExportPolicies.AllowPlaintextExport | CngExportPolicies.AllowExport | CngExportPolicies.AllowArchiving | CngExportPolicies.AllowPlaintextArchiving;
                        cp.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(keySize), CngPropertyOptions.None));
                        var key = await Task.Run(() => CngKey.Create(CngAlgorithm.Rsa, null, cp)).ConfigureAwait(false);
                        var blobType = CngKeyBlobFormat.GenericPrivateBlob;
                        var bytes = await Task.Run(() => key.Export(blobType)).ConfigureAwait(false);
                
                        var rsa = new RSACng(key);
                        var pubKey = rsa.ExportParameters(includePrivateParameters: false);
                        var pubKeyString = exportKeyToString(pubKey);
                
                        return new KeyGenerationResult
                        {
                            PublicKey = pubKey,
                            PrivateKeyCleartext = Convert.ToBase64String(bytes),
                            PublicKeyCleartext = pubKeyString,
                            PrivateBytes = bytes,
                            BlobFormat = blobType,
                            KeySize = keySize
                        };
                    }
                
                    private static string exportKeyToString(RSAParameters key)
                    {
                        string keyString;
                        var sw = new StringWriter();
                        var xs = new XmlSerializer(typeof(RSAParameters));
                        xs.Serialize(sw, key);
                        keyString = sw.ToString();
                        return keyString;
                    }
                
                    public void SavePrivateKeyToLocalMachine(KeyGenerationResult keyData, string keyName)
                    {
                        var myKSP = CngProvider.MicrosoftSoftwareKeyStorageProvider;
                        const bool MachineKey = false;
                
                        if (!CngKey.Exists(keyName, myKSP))
                        {
                            var keyParams = new CngKeyCreationParameters
                            {
                                ExportPolicy = CngExportPolicies.AllowPlaintextExport,
                                KeyCreationOptions = (MachineKey) ? CngKeyCreationOptions.MachineKey : CngKeyCreationOptions.None,
                                Provider = myKSP
                            };
                            keyParams.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(keyData.KeySize), CngPropertyOptions.None));
                            keyParams.Parameters.Add(new CngProperty(keyData.BlobFormat.Format, keyData.PrivateBytes, CngPropertyOptions.None));
                
                            CngKey.Create(CngAlgorithm.Rsa, keyName, keyParams);
                        }
                        else
                        {
                            throw new CryptographicException($"The key with the name '{keyName}' already exists!");
                        }
                    }
                

                這篇關于導入 RSA CngKey 并存儲在 MicrosoftSoftwareKeyStorageProvider 中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                  <bdo id='Dobt8'></bdo><ul id='Dobt8'></ul>
                • <i id='Dobt8'><tr id='Dobt8'><dt id='Dobt8'><q id='Dobt8'><span id='Dobt8'><b id='Dobt8'><form id='Dobt8'><ins id='Dobt8'></ins><ul id='Dobt8'></ul><sub id='Dobt8'></sub></form><legend id='Dobt8'></legend><bdo id='Dobt8'><pre id='Dobt8'><center id='Dobt8'></center></pre></bdo></b><th id='Dobt8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Dobt8'><tfoot id='Dobt8'></tfoot><dl id='Dobt8'><fieldset id='Dobt8'></fieldset></dl></div>

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

                  • <tfoot id='Dobt8'></tfoot>

                      1. <legend id='Dobt8'><style id='Dobt8'><dir id='Dobt8'><q id='Dobt8'></q></dir></style></legend>
                            <tbody id='Dobt8'></tbody>
                          主站蜘蛛池模板: 亚洲免费网 | 亚洲狠狠丁香婷婷综合久久久 | 久久婷婷av | 日本精品一区二区在线观看 | 网站黄色在线免费观看 | 精品国产一区二区三区性色 | 国产ts一区 | 一区视频 | 国产伦精品一区二区三区高清 | 最新中文在线视频 | 中文字幕 在线观看 | 日本免费一区二区三区四区 | 伊人热久久 | 中文字幕在线二区 | 日韩成人免费av | 亚洲精品第一国产综合野 | 国产伊人久久久 | 免费在线色 | 国产精品毛片无码 | 国产精品特级毛片一区二区三区 | 亚洲 欧美 日韩 在线 | 午夜精品久久久久久久久久久久久 | 欧美乱大交xxxxx另类电影 | 琪琪午夜伦伦电影福利片 | 精品欧美一区免费观看α√ | 97精品国产一区二区三区 | 国产亚洲欧美日韩精品一区二区三区 | 亚洲精选一区 | 日韩欧美中文字幕在线观看 | 亚洲精品自在在线观看 | 成人在线免费观看 | 久久亚洲国产精品 | 中文av在线播放 | 中文字幕一区二区视频 | 草久久久| 中文字幕一区二区三区四区不卡 | 中文字幕精 | 日韩欧美国产成人一区二区 | 放个毛片看看 | 国产精品a久久久久 | 中文字幕乱码亚洲精品一区 |