rsa加密 是非对称加密 需要公钥 与 私钥
这个公钥私钥的具体值需要与后端协商定下
rsa js代码如下
代码太多不插入了
html代码如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" /> <meta name="format-detection" content="telephone=no"> <title></title> <link rel="stylesheet" type="text/css" href="reset.css"/> </head> <style type="text/css"> #btn{ 100px; height: 30px; margin: 0 auto; } </style> <body> <button id="btn">加密</button> </body> <script src="rsa.min.js" charset="UTF-8"></script> <script src="zepto.min.js" charset="UTF-8"></script> <script> $("#btn").tap(function(){ console.log(C_encryption('ss')) }) function C_encryption (parameter){ var T_pub_key = "" +"-----BEGIN PUBLIC KEY----- " +"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDtu83H3VL73R9j4T2mpd95yaFL " +"qiGhd22dLvqqKZQkn/tVOOQgig8OThlsz3lHvtJJE/L49+IO/l0LXno9zbs1m2Nk " +"5po9jGu0DyUXq9EyEHDXJr4yI8aqHUy7pScnBOCoTQ7oe6Ji1lFFFN5foA55yPCE " +"GRlIYI46vGdv1MvuFQIDAQAB " +"-----END PUBLIC KEY-----" +""; var C_crypt = new JSEncrypt(); C_crypt.setPublicKey(T_pub_key); if(parameter==null||parameter==""){ console.log("加密参数错误"); }else{ return C_crypt.encrypt(parameter); } } </script> </html>