当前位置: 首页>>代码示例>>C#>>正文


C# RSACryptoServiceProvider.ImportParameters方法代码示例

本文整理汇总了C#中RSACryptoServiceProvider.ImportParameters方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.ImportParameters方法的具体用法?C# RSACryptoServiceProvider.ImportParameters怎么用?C# RSACryptoServiceProvider.ImportParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RSACryptoServiceProvider的用法示例。


在下文中一共展示了RSACryptoServiceProvider.ImportParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportImportPublicOnly

        public static void ExportImportPublicOnly()
        {
            byte[] expectedExport = ByteUtils.HexToByteArray(
                "0602000000a40000525341310004000001000100e19a01644b82962a224781d1f60c2cc373b"
                + "798df541343f63c638f45fa96e11049c8d9e88bd56483ec3c2d56e9460d2b1140191841761c1523840221b0e"
                + "b6401dc4d09c54bf75cea25d9e191572fb2ec92c3559b35b3ef3fa695171bb1fddeb469792e49f0d17c769d0"
                + "a37f6a4a6584af39878eb21f9ba9eae8be9c39eac6ae0");

            byte[] exported;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.CspTestKey);

                exported = rsa.ExportCspBlob(includePrivateParameters: false);
            }

            Assert.Equal(expectedExport, exported);

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportCspBlob(exported);

                byte[] exported2 = rsa.ExportCspBlob(includePrivateParameters: false);

                Assert.Equal(exported, exported2);

                Assert.Throws<CryptographicException>(() => rsa.ExportCspBlob(includePrivateParameters: true));
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:30,代码来源:ImportExportCspBlob.cs

示例2: LargeKeyCryptRoundtrip

        public static void LargeKeyCryptRoundtrip()
        {
            byte[] output;

            using (var rsa = new RSACryptoServiceProvider())
            {
                try
                {
                    rsa.ImportParameters(TestData.RSA16384Params);
                }
                catch (CryptographicException)
                {
                    // The key is pretty big, perhaps it was refused.
                    return;
                }

                byte[] crypt = rsa.Encrypt(TestData.HelloBytes, true);

                Assert.Equal(rsa.KeySize, crypt.Length * 8);

                output = rsa.Decrypt(crypt, true);
            }

            Assert.Equal(TestData.HelloBytes, output);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:25,代码来源:EncryptDecrypt.cs

示例3: LargeKeyImportExport

        public static void LargeKeyImportExport()
        {
            RSAParameters imported = TestData.RSA16384Params;

            using (RSA rsa = new RSACryptoServiceProvider())
            {
                try
                {
                    rsa.ImportParameters(imported);
                }
                catch (CryptographicException)
                {
                    // The key is pretty big, perhaps it was refused.
                    return;
                }

                RSAParameters exported = rsa.ExportParameters(false);

                Assert.Equal(exported.Modulus, imported.Modulus);
                Assert.Equal(exported.Exponent, imported.Exponent);
                Assert.Null(exported.D);

                exported = rsa.ExportParameters(true);

                AssertKeyEquals(ref imported, ref exported);
            }
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:27,代码来源:ImportExport.cs

示例4: PaddedExport

        public static void PaddedExport()
        {
            // OpenSSL's numeric type for the storage of RSA key parts disregards zero-valued
            // prefix bytes.
            //
            // The .NET 4.5 RSACryptoServiceProvider type verifies that all of the D breakdown
            // values (P, DP, Q, DQ, InverseQ) are exactly half the size of D (which is itself
            // the same size as Modulus).
            //
            // These two things, in combination, suggest that we ensure that all .NET
            // implementations of RSA export their keys to the fixed array size suggested by their
            // KeySize property.
            RSAParameters diminishedDPParamaters = TestData.DiminishedDPParamaters;
            RSAParameters exported;

            using (RSA rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(diminishedDPParamaters);
                exported = rsa.ExportParameters(true);
            }

            // DP is the most likely to fail, the rest just otherwise ensure that Export
            // isn't losing data.
            AssertKeyEquals(ref diminishedDPParamaters, ref exported);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:25,代码来源:ImportExport.cs

示例5: DecryptSavedAnswerUnusualExponent

        public static void DecryptSavedAnswerUnusualExponent()
        {
            byte[] cipherBytes =
            {
                0x55, 0x64, 0x05, 0xF7, 0xBF, 0x99, 0xD8, 0x07,
                0xD0, 0xAC, 0x1B, 0x1B, 0x60, 0x92, 0x57, 0x95,
                0x5D, 0xA4, 0x5B, 0x55, 0x0E, 0x12, 0x90, 0x24,
                0x86, 0x35, 0xEE, 0x6D, 0xB3, 0x46, 0x3A, 0xB0,
                0x3D, 0x67, 0xCF, 0xB3, 0xFA, 0x61, 0xBB, 0x90,
                0x6D, 0x6D, 0xF8, 0x90, 0x5D, 0x67, 0xD1, 0x8F,
                0x99, 0x6C, 0x31, 0xA2, 0x2C, 0x8E, 0x99, 0x7E,
                0x75, 0xC5, 0x26, 0x71, 0xD1, 0xB0, 0xA5, 0x41,
                0x67, 0x19, 0xF7, 0x40, 0x04, 0xBE, 0xB2, 0xC0,
                0x97, 0xFB, 0xF6, 0xD4, 0xEF, 0x48, 0x5B, 0x93,
                0x81, 0xF8, 0xE1, 0x6A, 0x0E, 0xA0, 0x74, 0x6B,
                0x99, 0xC6, 0x23, 0xF5, 0x02, 0xDE, 0x47, 0x49,
                0x1E, 0x9D, 0xAE, 0x55, 0x20, 0xB5, 0xDE, 0xA0,
                0x04, 0x32, 0x37, 0x4B, 0x24, 0xE4, 0x64, 0x1B,
                0x1B, 0x4B, 0xC0, 0xC7, 0x30, 0x08, 0xA6, 0xAE,
                0x50, 0x86, 0x08, 0x34, 0x70, 0xE5, 0xB0, 0x3B,
            };

            byte[] output;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.UnusualExponentParameters);
                output = rsa.Decrypt(cipherBytes, true);
            }

            Assert.Equal(TestData.HelloBytes, output);
        }
开发者ID:AustinWise,项目名称:corefx,代码行数:32,代码来源:EncryptDecrypt.cs

示例6: DecryptSavedAnswer

        public static void DecryptSavedAnswer()
        {
            byte[] cipherBytes =
            {
                0x35, 0x6F, 0x8F, 0x2C, 0x4D, 0x1A, 0xAC, 0x6D,
                0xE7, 0x52, 0xA5, 0xDF, 0x26, 0x54, 0xA6, 0x34,
                0xF5, 0xBB, 0x14, 0x26, 0x1C, 0xE4, 0xDC, 0xA2,
                0xD8, 0x4D, 0x8F, 0x1C, 0x55, 0xD4, 0xC7, 0xA7,
                0xF2, 0x3C, 0x99, 0x77, 0x9F, 0xE4, 0xB7, 0x34,
                0xA6, 0x28, 0xB2, 0xC4, 0xFB, 0x6F, 0x85, 0xCA,
                0x19, 0x21, 0xCA, 0xC1, 0xA7, 0x8D, 0xAE, 0x95,
                0xAB, 0x9B, 0xA9, 0x88, 0x5B, 0x44, 0xC6, 0x9B,
                0x44, 0x26, 0x71, 0x5D, 0x02, 0x3F, 0x43, 0x42,
                0xEF, 0x4E, 0xEE, 0x09, 0x87, 0xEF, 0xCD, 0xCF,
                0xF9, 0x88, 0x99, 0xE8, 0x49, 0xF7, 0x8F, 0x9B,
                0x59, 0x68, 0x20, 0xF3, 0xA7, 0xB2, 0x94, 0xA4,
                0x23, 0x70, 0x83, 0xD9, 0xAC, 0xE7, 0x5E, 0xEE,
                0xE9, 0x7B, 0xE4, 0x4F, 0x73, 0x2E, 0x9B, 0xD8,
                0x2A, 0x75, 0xFB, 0x6C, 0xB9, 0x39, 0x6D, 0x72,
                0x8A, 0x9C, 0xCD, 0x58, 0x1A, 0x27, 0x79, 0x97,
            };

            byte[] output;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.RSA1024Params);
                output = rsa.Decrypt(cipherBytes, true);
            }

            Assert.Equal(TestData.HelloBytes, output);
        }
开发者ID:AustinWise,项目名称:corefx,代码行数:32,代码来源:EncryptDecrypt.cs

示例7: ToPublicKeyXml

 public static string ToPublicKeyXml(this RSAParameters publicKey)
 {
     using (var rsa = new RSACryptoServiceProvider())
     {
         rsa.ImportParameters(publicKey);
         return rsa.ToXmlString(includePrivateParameters: false);
     }
 }
开发者ID:pkmnfrk,项目名称:ServiceStack,代码行数:8,代码来源:CryptUtils.cs

示例8: FromPrivateRSAParameters

 public static string FromPrivateRSAParameters(this RSAParameters privateKey)
 {
     using (var rsa = new RSACryptoServiceProvider())
     {
         rsa.ImportParameters(privateKey);
         return rsa.ToXmlString(includePrivateParameters: true);
     }
 }
开发者ID:pkmnfrk,项目名称:ServiceStack,代码行数:8,代码来源:CryptUtils.cs

示例9: PublicOnly_WithPrivateKey

        public static void PublicOnly_WithPrivateKey()
        {
            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.RSA1024Params);

                Assert.False(rsa.PublicOnly);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:RSACryptoServiceProviderTests.cs

示例10: AlgorithmLookups

        public static void AlgorithmLookups(string primaryId, object halg)
        {
            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.RSA2048Params);

                byte[] primary = rsa.SignData(s_dataToSign, primaryId);
                byte[] lookup = rsa.SignData(s_dataToSign, halg);

                Assert.Equal(primary, lookup);
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:12,代码来源:RSACryptoServiceProviderBackCompat.cs

示例11: checkSign

 /// <summary>
 /// 验签
 /// </summary>
 /// <param name="content">待验签字符串</param>
 /// <param name="signedString">签名</param>
 /// <param name="publicKey">公钥</param>
 /// <param name="input_charset">编码格式</param>
 /// <returns>true(通过),false(不通过)</returns>
 public static bool checkSign(string content, string signedString, string publicKey, string input_charset)
 {
     bool result = false;
         byte[] Data = Encoding.GetEncoding(input_charset).GetBytes(content);
         byte[] data = Convert.FromBase64String(signedString);
         RSAParameters paraPub = ConvertFromPublicKey(publicKey);
         RSACryptoServiceProvider rsaPub = new RSACryptoServiceProvider();
         rsaPub.ImportParameters(paraPub);
         SHA1 sh = new SHA1CryptoServiceProvider();
         result = rsaPub.VerifyData(Data, sh, data);
         return result;
 }
开发者ID:cangjie,项目名称:lq_yeepay,代码行数:20,代码来源:RSA.cs

示例12: PublicOnly_WithNoPrivate

        public static void PublicOnly_WithNoPrivate()
        {
            using (var rsa = new RSACryptoServiceProvider())
            {
                RSAParameters publicParams = new RSAParameters
                {
                    Modulus = TestData.RSA1024Params.Modulus,
                    Exponent = TestData.RSA1024Params.Exponent,
                };

                rsa.ImportParameters(publicParams);
                Assert.True(rsa.PublicOnly);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:14,代码来源:RSACryptoServiceProviderTests.cs

示例13: AlgorithmLookups

        public static void AlgorithmLookups(string primaryId, object halg)
        {
            byte[] data = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.RSA2048Params);

                byte[] primary = rsa.SignData(data, primaryId);
                byte[] lookup = rsa.SignData(data, halg);

                Assert.Equal(primary, lookup);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:RSACryptoServiceProviderBackCompat.cs

示例14: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        var code = Request.QueryString["code"];


        //send request to github server to get access token
        HttpWebRequest req = WebRequest.Create("https://github.com/login/oauth/access_token?client_id=TODO:<your own client id>&client_secret=TODO:<your own client secret>&code=" + code) as HttpWebRequest;
        req.Method = "POST";
        HttpWebResponse rsps = req.GetResponse() as HttpWebResponse;
        var str = new StreamReader(rsps.GetResponseStream()).ReadToEnd();
        Match m = Regex.Match(str, "access_token=([^&]+)&token_type=([^&]+)");


        //RSA encrypt access token with public key from browser side
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
        RSAParameters publicKey = new RSAParameters();
        publicKey.Modulus = literal2bytes(Request.Cookies["modulus"].Value);
        publicKey.Exponent = literal2bytes(Request.Cookies["exponent"].Value);
        rsa.ImportParameters(publicKey);
        byte[] result = rsa.Encrypt(Encoding.UTF8.GetBytes(m.Groups[1].ToString()), false);
        StringBuilder access_token = new StringBuilder();
        for (var i = 0; i < result.Length; i++)
        {
            access_token.Append(result[i].ToString("x2"));
        }

        //write encrypted access_token back into cookie
        HttpCookie cookie = new HttpCookie("access_token");
        DateTime dt = DateTime.Now;
        TimeSpan ts = new TimeSpan(0, 0, 0, 0);
        cookie.Expires = dt.Add(ts);
        cookie.Value = access_token.ToString();
        Response.AppendCookie(cookie);


        cookie = new HttpCookie("token_type");
        dt = DateTime.Now;
        ts = new TimeSpan(0, 0, 0, 0);
        cookie.Expires = dt.Add(ts);
        cookie.Value = m.Groups[2].ToString();
        Response.AppendCookie(cookie);

        //now jump back, only the browser side could decrypt the access_token from cookie
        Response.Redirect("TODO:<your own address>");
    }
开发者ID:esironal,项目名称:github.wind,代码行数:45,代码来源:auth.aspx.cs

示例15: RSAEncrypt

    public static byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo)
    {
        try
        {
            byte[] encryptedData;
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                RSA.ImportParameters(RSAKeyInfo);
                encryptedData = RSA.Encrypt(DataToEncrypt, false);
            }
            return encryptedData;
        }
        catch (CryptographicException e)
        {
            Console.WriteLine(e.Message);

            return null;
        }
    }
开发者ID:saeidghoreshi,项目名称:partition1,代码行数:19,代码来源:Program.cs


注:本文中的RSACryptoServiceProvider.ImportParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。