当前位置: 首页 > news >正文

外网网站管理制度建设wordpress编辑器自定义按钮

外网网站管理制度建设,wordpress编辑器自定义按钮,毕设做网站工作量够吗,欧美风格企业网站本人整理网上的。好多网上的调不通。在这里把调试好的贴出来。 1. 异步获取公钥#xff08;后台获取#xff09;#xff1b;你也可以将公钥串写在页面上#xff1b; var publicKey null; $.ajax({ url: ctx/userLogin.do?methodgetRSAPublicKey, #xf…本人整理网上的。好多网上的调不通。在这里把调试好的贴出来。 1.   异步获取公钥后台获取你也可以将公钥串写在页面上 var publicKey null; $.ajax({ url: ctx/userLogin.do?methodgetRSAPublicKey, 请求地址 type: post, dataType: text, async:false, success: function(data) { if(data) publicKey data; } }); 2. 前段加密 引入这个  jsencrypt.min.js   var encrypt new JSEncrypt(); encrypt.setPublicKey(publicKey); // 设置公钥 var password11 encrypt.encrypt(password);// 加密 password 是你页面获取的值   password11 是加密后的值  生成随机串 3. RSA 工具类  我这里引入了 commons-codec 的依赖 1.4版本的 import java.io.ByteArrayOutputStream;import java.io.UnsupportedEncodingException;import java.security.KeyFactory;import java.security.KeyPair;import java.security.KeyPairGenerator;import java.security.NoSuchAlgorithmException;import java.security.PrivateKey;import java.security.Provider;import java.security.PublicKey;import java.security.SecureRandom;import java.security.Security;import java.security.interfaces.RSAPrivateKey;import java.security.interfaces.RSAPublicKey;import java.security.spec.InvalidKeySpecException;import java.security.spec.PKCS8EncodedKeySpec; import javax.crypto.Cipher; import org.apache.commons.codec.binary.Base64;import org.apache.commons.io.IOUtils; public class RSAUtils1 { public static final String CHARSET UTF-8; public static final String RSA_ALGORITHM RSA; private static final KeyPair keyPair initKey(); /** * 初始化方法产生key pair提供provider和random * return KeyPair instance */ private static KeyPair initKey() { try { //添加provider Provider provider new org.bouncycastle.jce.provider.BouncyCastleProvider(); Security.addProvider(provider); //产生用于安全加密的随机数 SecureRandom random new SecureRandom(); KeyPairGenerator generator KeyPairGenerator.getInstance(RSA, provider); generator.initialize(1024, random); return generator.generateKeyPair(); } catch(Exception e) { throw new RuntimeException(e); } } /** * 产生public key * return public key字符串 */ public static String generateBase64PublicKey() { PublicKey publicKey (RSAPublicKey)keyPair.getPublic(); //encodeBase64(): Encodes binary data using the base64 //algorithm but does not chunk the output. //getEncoded():返回key的原始编码形式 return new String(Base64.encodeBase64(publicKey.getEncoded())); } /** * 产生private key * * return private key字符串 */ public static String generateBase64PrivateKey(){ PrivateKey privateKey keyPair.getPrivate(); return new String(Base64.encodeBase64(privateKey.getEncoded())); } /** * 私钥解密 * param data * param privateKey * return */ public static String privateDecrypt(String data){ try{ RSAPrivateKey privateKey getPrivateKey(generateBase64PrivateKey()); Cipher cipher Cipher.getInstance(RSA_ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, privateKey); return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(data), privateKey.getModulus().bitLength()), CHARSET); }catch(Exception e){ throw new RuntimeException(解密字符串[ data ]时遇到异常, e); } } /** * 得到私钥 * param privateKey 密钥字符串经过base64编码 * throws Exception */ public static RSAPrivateKey getPrivateKey(String privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException { //通过PKCS#8编码的Key指令获得私钥对象 KeyFactory keyFactory KeyFactory.getInstance(RSA_ALGORITHM); PKCS8EncodedKeySpec pkcs8KeySpec new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)); RSAPrivateKey key (RSAPrivateKey) keyFactory.generatePrivate(pkcs8KeySpec); return key; } private static byte[] rsaSplitCodec(Cipher cipher, int opmode, byte[] datas, int keySize){ int maxBlock 0; if(opmode Cipher.DECRYPT_MODE){ maxBlock keySize / 8; }else{ maxBlock keySize / 8 - 11; } ByteArrayOutputStream out new ByteArrayOutputStream(); int offSet 0; byte[] buff; int i 0; try{ while(datas.length offSet){ if(datas.length-offSet maxBlock){ buff cipher.doFinal(datas, offSet, maxBlock); }else{ buff cipher.doFinal(datas, offSet, datas.length-offSet); } out.write(buff, 0, buff.length); i; offSet i * maxBlock; } }catch(Exception e){ throw new RuntimeException(加解密阀值为[maxBlock]的数据时发生异常, e); } byte[] resultDatas out.toByteArray(); IOUtils.closeQuietly(out); return resultDatas; } public static void main(String[] args) { // 获得公钥 私钥对 System.out.println(公钥generateBase64PublicKey()); System.out.println(秘钥generateBase64PrivateKey()); }} 4. 给前台返回公钥 RequestMapping(params methodgetRSAPublicKey) public void getRSAPublicKey(HttpServletRequest request,HttpServletResponse response){ PrintWriter writer; try { writer response.getWriter(); String publicKey RSAUtils1.generateBase64PublicKey(); writer.write(publicKey); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 5.解密 //先对前端密码进行RSA解密 password password.replace( ,);  加密的数据放在Url传递时会将“”变成空格这里变回来。 System.out.println(解密前password); password RSAUtils1.privateDecrypt(password); System.out.println(解密后密码password);   结束。谢谢交流评论。  转载于:https://www.cnblogs.com/m5n7xiao/p/9225065.html
http://www.pierceye.com/news/820620/

相关文章:

  • 襄垣网站建设宝塔面板怎么搭建网站
  • 电影网站源码access广州网站建设排名一览表
  • 做论坛网站多少钱企业做网站有用吗天涯
  • 做网站价格多少钱网站设计培训课程
  • 做网站找什么公司好淘宝客网站可以做百度推广
  • 北京网站建设首选石榴汇企业vi设计一整套
  • 做网站较好的公司c 网站开发培训
  • 一个云主机怎么挂两个网站建立网站要准备多少钱
  • 贵阳网站建设在线学做凉菜冷菜的网站
  • 购销网站建设视频百度云广东省深圳市龙华区
  • 做建材外贸哪个网站比较好乐清比较好的设计公司
  • 做电影种子下载网站违法吗桂林网站建设凡森网络
  • 云南省建设厅专家注册网站织梦网站怎么做下载地址
  • 你们需要网站建设搜索引擎调词平台多少钱
  • 北京建设官方网站百度公司官网首页
  • 四川禾力建设工程质量检测有限公司网站惠州有哪些做网站的公司
  • 深圳手机网站设计公司php网站安装图解
  • 网站开发 工作职责平面设计和室内设计有什么区别
  • 防城港门面做网站的代做网站跳转
  • 珠海网站系统建设苏州房地产网站建设
  • 长治网站建设培训文件检察院网站建设
  • 茶文化网站制作asa8.4 做网站映射
  • 网站建设步骤 文档富阳做网站洛洛科技
  • 列举网站建设的SEO策略广东建设行业招聘 什么网站
  • 免费社区建站系统seo是指什么
  • 网站建设实训的认识小企业网站建设哪里做得好
  • 无锡seo网站排名优化牟平建设企业网站
  • 网络营销好找工作吗成都seo优化公司排名
  • 网站换关键词山西网站备案
  • 网站微信建设运维经验深圳罗湖企业网站