首页 > 其他 > 详细

RSA公钥加密

时间:2016-06-04 19:35:19      阅读:124      评论:0      收藏:0      [点我收藏+]
 1         /// <summary>
 2         /// RSA公钥加密
 3         /// </summary>
 4         /// <param name="content">待加密文本</param>
 5         /// <param name="publickey">RSA公钥</param>
 6         /// <returns></returns>
 7         public static string RSAEncrypt(string content, string publickey)
 8         {
 9             string result = "";
10             try
11             {
12                 RSACryptoServiceProvider.UseMachineKeyStore = true;//防止出现 找不到指定文件 错误
13                 RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
14                 RSAParameters RSAKeyInfo = new RSAParameters();
15                 byte[] bytearr = Convert.FromBase64String(publickey);
16                 RSAKeyInfo.Modulus = bytearr.ToList().GetRange(29, bytearr.Length - 34).ToArray();
17                 RSAKeyInfo.Exponent = Convert.FromBase64String("AQAB");
18                 RSA.ImportParameters(RSAKeyInfo);
19                 byte[] bytes = RSA.Encrypt(UTF8Encoding.UTF8.GetBytes(content), false);
20                 result = Convert.ToBase64String(bytes);
21             }
22             catch (Exception ex)
23             {
24                 log.Warn("RSA加密出错,加密文本:" + content + ",加密公钥:" + publickey + ",错误信息:" + ex.Message);
25             }
26             return result;
27         }

 

RSA公钥加密

原文:http://www.cnblogs.com/yixuehan/p/5559316.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!