zoukankan      html  css  js  c++  java
  • c#,js, RSA加密签名常用方法汇总;

    1,c# .net framework RSA 加密签名;  

    // privatekey 私钥字符串

      byte[] keyData = Convert.FromBase64String(privatekey);
      using (CngKey cngKey = CngKey.Import(keyData, CngKeyBlobFormat.Pkcs8PrivateBlob))
      using (RSACng rsa = new RSACng(cngKey))
      {
        byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
        return Convert.ToBase64String(rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
      }

    2,c# .net 5 RSA 加密签名;

    //跨平台可用; 
    // privatekey 私钥字符串
    byte[] keyData = Convert.FromBase64String(privatekey);
    int len = keyData.Length;
    var r = System.Security.Cryptography.RSA.Create();
    r.ImportPkcs8PrivateKey(keyData, out len);
    //message 待加密字符串 byte[] data
    = System.Text.Encoding.UTF8.GetBytes(message); r.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

    3,js RSA 加密签名;

        
        <script src="../lib/myset/base64.min.js"></script>
        <script src="../lib/myset/crypto-js.js"></script>
        <script>

         //Math.SHA256

         var pk = '公钥';
         var sign = new JSEncrypt();    

         sign.setPublickKey(pk)

         //sign.setPrivateKey(pk);

         var signature = sign.sign('message', CryptoJS.SHA256, "sha256");

         console.info(signature);

        </script>
  • 相关阅读:
    ajax网站
    iTextSharp和jQuery和.Net教程
    搜索引擎学习资料
    tooltip 效果
    ccnet+web deploy远程发布
    创建报表时出现“缺少DataSetName属性的值”
    virtualBox 虚拟机相关设置
    数据库更新数据表时被禁止
    ACL
    windows server 添加IIS
  • 原文地址:https://www.cnblogs.com/llsfast/p/15128416.html
Copyright © 2011-2022 走看看