js\java 通过算法加密后,再base64
来源:互联网 发布:telnet 80端口失败 编辑:程序博客网 时间:2024/05/20 16:33
java 通过算法加密后,再base64
/** * 授权播放 * @param request * @param response * @param map * @throws Exception */ @RequestMapping(value = "/get/player/sign", method = { RequestMethod.GET, RequestMethod.POST }) @ResponseBody public String getPlayerSign(HttpServletRequest request, HttpServletResponse response, Map<String, Object> map) throws Exception { ParamUtil pu = new ParamUtil(request); String vid = ServletRequestUtils.getStringParameter(request, "vid", ""); String code = ServletRequestUtils.getStringParameter(request, "code", ""); String username = ServletRequestUtils.getStringParameter(request, "username", ""); String status = ServletRequestUtils.getStringParameter(request, "status", ""); String t = ServletRequestUtils.getStringParameter(request, "t", ""); DOC doc = new DOC(); doc.put("error", "0"); String userid=vid.substring(0,10); CcUser customers=null; customers = ccUserService.getByUserId(userid); if (customers!=null) { //通过writetoken验证 String s=vid+customers.getSecretkey()+username+code+status+t; String sign=MD5Util.getMD5String(s); logger.info("处理前的签名:"+sign); //对签名进行处理 sign=signEncode(sign); logger.info("encode后的签名:"+sign); sign=new Base64Encoder().encode(sign.getBytes()); doc.put("error", "0");//没有writetoken对应的用户 doc.put("sign", sign); }else{ doc.put("error", "6");//没有writetoken对应的用户 doc.put("result", "没有writetoken对应的用户"); } outPrintStream(JsonUtil.docToJson(doc), response); return null; } /** * 对签名编码进行处理 */ public String signEncode(String sign){ String key = "lpmkenjibhuvgycftxdrzsoawq0126783459"; String alphabet, coded; int index; char ch; alphabet = "abcdofghijklnmepqrstuvwxyz0123456789"; coded = "" + alphabet.charAt((int) (Math.random()*alphabet.length())); for (int i = 0; i < sign.length(); i++) { // for as many letters as there are ch = sign.charAt(i); // access the letter in the message index = alphabet.indexOf(ch); // find its position in alphabet if (index == -1) { // if it's not a letter, coded = coded + ch; // then leave it as is & add } // otherwise, else { // find the corresponding coded = coded + key.charAt(index); // letter in the key & add } } return coded; } public static void main(String args[]) throws UnsupportedEncodingException{ String sgin="bjZjbDYzbjM5ODBjMG0zNm5jazFrNzE1MjRtMTIzNTgw"; byte[] b=org.apache.commons.codec.binary.Base64.encodeBase64(sgin.getBytes()); byte[] a=org.apache.commons.codec.binary.Base64.decodeBase64(sgin); System.out.println(signDecode(new String(a, "utf-8"))); } public static String signDecode(String message){ String key="lpmkenjibhuvgycftxdrzsoawq0126783459"; String alphabet, coded; char ch; int index; int i; alphabet = "abcdofghijklnmepqrstuvwxyz0123456789"; message = message.substring(1); coded = ""; for (i = 0; i < message.length(); i++) { // for as many letters as there are ch = message.charAt(i); // access the letter in the message index = key.indexOf(ch); // find its position in alphabet if (index == -1) { // if it's not a letter, coded = coded + ch; // then leave it as is & add } // otherwise, else { // find the corresponding coded = coded + alphabet.charAt(index); // letter in the key & add } } return coded; }
js加密,解密
<p id="encrypt"></p><script> function Encode(key, message) // Given : key is a string of the 26 letters in arbitrary order, // message is the string to be encoded using the key // Returns: the coded version of message using the substitution key { var alphabet, coded, i, ch, index; alphabet = "abcdofghijklnmepqrstuvwxyz0123456789"; coded = "" + alphabet.charAt(parseInt(Math.random()*alphabet.length)); for (i = 0; i < message.length; i++) { // for as many letters as there are ch = message.charAt(i); // access the letter in the message index = alphabet.indexOf(ch); // find its position in alphabet if (index == -1) { // if it's not a letter, coded = coded + ch; // then leave it as is & add } // otherwise, else { // find the corresponding coded = coded + key.charAt(index); // letter in the key & add } } return coded; } function Decode(key,message){ var alphabet, coded, i, ch, index; alphabet = "abcdofghijklnmepqrstuvwxyz0123456789"; message = message.substr(1); coded = ""; for (i = 0; i < message.length; i++) { // for as many letters as there are ch = message.charAt(i); // access the letter in the message index = key.indexOf(ch); // find its position in alphabet if (index == -1) { // if it's not a letter, coded = coded + ch; // then leave it as is & add } // otherwise, else { // find the corresponding coded = coded + alphabet.charAt(index); // letter in the key & add } } return coded; } var encodeString = Encode("lpmkenjibhuvgycftxdrzsoawq0126783459","05714ecace14c04326f27aa638aa4c2e_0"); var decodeString = Decode("lpmkenjibhuvgycftxdrzsoawq0126783459",encodeString); var explain = ">>>encodeString: " + encodeString +" >>decodeString: " + decodeString ; console.log(explain); var encrypt = document.getElementById("encrypt"); encrypt.innerHTML = explain;</script>
0 0
- js\java 通过算法加密后,再base64
- java 加密之 Base64 算法
- Java加密解密算法-Base64加密解密
- java 通过AES+base64加密-解密
- js、java的base64相互加密、解密
- java关于base64加密解密的算法!
- java加密解密研究3、Base64算法
- Java加密-Base64、消息摘要算法
- [Java--加密算法]--base64加密的算法实现
- js通过Base64 解析html,后台返回的加密字符串
- JAVA中MD5加密和Base64加密解密算法
- MD5加密 Base64加密和解密算法 java
- 单向加密——使用java加密Base64算法
- Js base64 加密解密
- js base64 加密
- js,base64加密
- js base64加密
- JS Base64加密
- Oracle日志清理
- 【解题报告】滑雪
- SharePoint2016 New Feature (Preview) - 性能及限制优化
- JAVA 性能优化
- ZJU 3430 Detect the Virus AC自动机
- js\java 通过算法加密后,再base64
- 原始LSH算法trick
- iOS个人整理20-UITableViewCell自定义,cell高度的自适应(纯代码)
- JasperReport 报表在SpringMVC WEB项目中的应用(JavaBean作为数据源)
- (总结)Nginx配置文件nginx.conf中文详解
- php的strlen和mb_strlen的区别
- JSON序列化与反序列
- 【解题报告】传球游戏
- ELK