Permalink
Browse files

des to 3des

  • Loading branch information...
FLY的狐狸
FLY的狐狸 committed May 1, 2017
1 parent 0414643 commit e3b20477bf10a04900a2d1b72c0901f92c60b33a
View
@@ -310,8 +310,8 @@ CREATE TABLE `sys_user` (
-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO `sys_user` VALUES ('1', 'admin', '1RHFCLt64uOOViCTzgSaww==', '系统管理员', '1', '1', '10', null, null, 'zcool321@sina.com', '123', null, null, '时间是最好的老师,但遗憾的是——最后他把所有的学生都弄死了', 'flat', '5', '1', '2016-06-06 06:06:06', '1');
INSERT INTO `sys_user` VALUES ('2', 'testapi', 'ldKI9edsQVM=', 'api测试', '1', '5', '10', null, null, null, null, null, null, null, 'default', '0', '1', '2017-03-19 20:41:25', '1');
INSERT INTO `sys_user` VALUES ('1', 'admin', 'Iuy8AguV5T7Vm08po+I4Gg==', '系统管理员', '1', '1', '10', null, null, 'zcool321@sina.com', '123', null, null, '时间是最好的老师,但遗憾的是——最后他把所有的学生都弄死了', 'flat', '5', '1', '2016-06-06 06:06:06', '1');
INSERT INTO `sys_user` VALUES ('2', 'testapi', 'EY3JNDE7nu8=', 'api测试', '1', '5', '10', null, null, null, null, null, null, null, 'default', '0', '1', '2017-03-19 20:41:25', '1');
-- ----------------------------
-- Table structure for `sys_user_role`
@@ -16,10 +16,6 @@
*/
package com.jflyfox.component.base;
import java.io.File;
import java.util.List;
import java.util.Map;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jflyfox.component.util.JFlyFoxUtils;
@@ -43,7 +39,10 @@
import com.jflyfox.util.StrUtils;
import com.jflyfox.util.cache.Cache;
import com.jflyfox.util.cache.CacheManager;
import com.jflyfox.util.encrypt.DESUtils;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* 项目BaseControler
@@ -54,8 +53,6 @@
*/
public abstract class BaseProjectController extends BaseController {
private static final DESUtils COOKIE_DES = new DESUtils("ffcookie");
public void renderAuto(String view) {
String path = getAutoPath(view);
@@ -102,7 +99,7 @@ public SessionUser getSessionUser() {
if (sysUser == null) {
String cookieContent = getCookie(Attr.SESSION_NAME);
if (cookieContent != null) {
String key = COOKIE_DES.decryptString(cookieContent);
String key = JFlyFoxUtils.cookieDecrypt(cookieContent);
if (StrUtils.isNotEmpty(key) && key.split(",").length == 2) {
int userid = NumberUtils.parseInt(key.split(",")[0]);
String password = key.split(",")[1];
@@ -136,7 +133,7 @@ public SessionUser setSessionUser(SessionUser user) {
// 设置cookie,用id+password作为
SysUser sysUser = (SysUser) user;
String key = sysUser.getUserid() + "," + user.getStr("password");
String cookieContent = COOKIE_DES.encryptString(key);
String cookieContent = JFlyFoxUtils.cookieEncrypt(key);
setCookie(Attr.SESSION_NAME, cookieContent, 7 * 24 * 60 * 60);
// 如果是管理员 设置菜单权限
if (user.getInt("usertype") == 1 || user.getInt("usertype") == 2) {
@@ -1,11 +1,11 @@
package com.jflyfox.component.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.jflyfox.util.Config;
import com.jflyfox.util.StrUtils;
import com.jflyfox.util.encrypt.DESUtils;
import com.jflyfox.util.encrypt.DES3Utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JFlyFoxUtils {
@@ -93,14 +93,19 @@
public static final int MATERIAL_TYPE_FOLDER = 106; // 栏目
private static final DESUtils des = new DESUtils("flyfoxxx");
private static final DES3Utils des = new DES3Utils("flyoffox");
// admin:1RHFCLt64uOOViCTzgSaww== test:ldKI9edsQVM=
public static void main(String[] args) {
String password = "admin123";
String tmp = passwordEncrypt(password);
System.out.println(tmp);
System.out.println(passwordDecrypt(tmp));
password = "123456";
tmp = passwordEncrypt(password);
System.out.println(tmp);
System.out.println(passwordDecrypt(tmp));
}
/**
@@ -127,6 +132,30 @@ public static String passwordDecrypt(String encryptPassword) {
return des.decryptString(encryptPassword);
}
/**
* cookie编码
*
* 2015年2月25日 下午2:22:08 flyfox 369191470@qq.com
*
* @param password
* @return
*/
public static String cookieEncrypt(String password) {
return des.encryptString(password);
}
/**
* cookie解码
*
* 2015年2月25日 下午2:22:13 flyfox 369191470@qq.com
*
* @param encryptPassword
* @return
*/
public static String cookieDecrypt(String encryptPassword) {
return des.decryptString(encryptPassword);
}
/**
* 默认密码
*

0 comments on commit e3b2047

Please sign in to comment.