zoukankan      html  css  js  c++  java
  • RSA公钥加密

     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         }
  • 相关阅读:
    今日总结
    微任务与宏任务
    20171128微信小程序
    20171128-微信小程序之点餐
    git
    第二次学习Javascript笔记
    base64图片
    网页布局基础-css版
    StuQ技能图谱——前端
    前端开发工具
  • 原文地址:https://www.cnblogs.com/yixuehan/p/5559316.html
Copyright © 2011-2022 走看看