<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                本文實例作者:冀云 本文整理作者:楊紅偉 ## (一)官方地址: https://github.com/travist/jsencrypt ## (二)本站代碼 **本站代碼** https://gitee.com/hongweizhiyuan/ijquery/tree/master/signature **本站測試及調試** http://www.ijquery.cn/plugin/jsencrypt/rsa.html ![mark](http://qiniu.newthink.cc/blog/180925/b75F1DGiJi.png) ## 原理: ![mark](http://qiniu.newthink.cc/blog/180925/b58ide9D6E.png) ## (三)最簡DEMO ### 1、HTML ``` <h2>第一步:獲取公鑰</h2> <button id="getKey">點擊獲取公鑰</button> <hr/> <h2>第二步:將本地數據加密后,在遠程進行解密</h2> <input id="dataText1" placeholder="本地數據"/> <button id="sendButton">發送</button> <input id="dataText2" placeholder="遠程解密"/> ``` ### 2、JS ``` (function(window) { 'use strict'; var rsa = function(params) { $.extend(this.params, params); this._init(); }; rsa.prototype = { params: { publicKey: '', }, _init: function() { var that = this; that.getKeyClick(); that.sendButton(); }, /** * 獲取公鑰 */ getKeyClick: function() { var that = this; $('#getKey').click(function() { $.get('testrsa.php', {act: 'get'}, function (result) { result = $.parseJSON(result); // 保存公鑰 that.params.publicKey = result['publicKey']; }); }); }, /** * 發送測試數據 */ sendButton: function() { var that = this; $('#sendButton').click(function() { var dataText1 = $('#dataText1').val(); // step1:本地加密 var encrypt = new JSEncrypt(); encrypt.setPublicKey(that.params.publicKey); var encrypted = encrypt.encrypt(dataText1); console.log(encrypted); // step2:服務器上私鑰解密 $.get('testrsa.php', {act: 'data',dataText: encrypted}, function (result) { result = $.parseJSON(result); console.log(result['code']); console.log(result['decrypted']); $('#dataText2').val(result['decrypted']); }); }); } }; window.rsa = rsa; })(window); ``` ### 3、PHP ``` <?php require_once('test.php'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); $key = array(); $act = $_REQUEST['act']; $rsa = new Rsa(); session_start(); if ( $act == 'get' ) { $key = $rsa->getKeys(); $arr = array('code'=>200, 'publicKey'=>$key['publicKey']); // echo $key['publicKey']; echo json_encode($arr); $_SESSION['publickey'] = $key['publicKey']; $_SESSION['privateKey'] = $key['privateKey']; } else if ( $act == 'data' ) { $dataText = $_REQUEST['dataText']; $decrypted = $rsa->decrypt($dataText, $_SESSION['privateKey']); $arr = array('code'=>200, 'decrypted'=>$decrypted); echo json_encode($arr); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看