当前位置: 首页>>代码示例>>Java>>正文


Java Md5Hash类代码示例

本文整理汇总了Java中org.apache.shiro.crypto.hash.Md5Hash的典型用法代码示例。如果您正苦于以下问题:Java Md5Hash类的具体用法?Java Md5Hash怎么用?Java Md5Hash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Md5Hash类属于org.apache.shiro.crypto.hash包,在下文中一共展示了Md5Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: register

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@ApiOperation("用户注册")
@PostMapping(value = "/register")
public ResponseEntity register(@RequestBody @Valid IndexRegisterFormat format) {
    // 检查用户是否存在
    UserEntity userEntity = userService.getUserByEmail(format.getEmail());
    if (userEntity != null) {
        throw new WebErrorException("邮箱已经注册");
    }

    // 注册用户
    int uid = userService.addUser(format.getEmail(),
            format.getNickname(),
            new Md5Hash(format.getPassword()).toString(),
            System.currentTimeMillis());
    if (uid == 0) {
        throw new WebErrorException("注册失败");
    }
    return new ResponseEntity("注册成功", uid);
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:20,代码来源:IndexController.java

示例2: login

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@ApiOperation("用户登入")
@PostMapping("/login")
public ResponseEntity login(@RequestBody @Valid IndexLoginFormat format) {
    UserEntity userEntity = userService.getUserByLogin(format.getEmail(),
            new Md5Hash(format.getPassword()).toString());
    if (userEntity == null)
        throw new WebErrorException("用户名密码错误");

    JSONArray array = userEntity.getPermission();
    Iterator<Object> it = array.iterator();
    Set<String> permission = new HashSet<>();
    while (it.hasNext()) {
        permission.add(it.next().toString());
    }
    String token = JWTUtil.sign(userEntity.getUid(), userEntity.getRole(), permission, userEntity.getPassword());
    Cache<String, String> authCache = CacheController.getAuthCache();
    authCache.put(token, userEntity.getPassword());

    return new ResponseEntity("登入成功", token);
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:21,代码来源:IndexController.java

示例3: main

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
public static void main(String[] args) { 
    String password = "admin"; 
    String cipherText = encrytHex(password); 
    System.out.println(password + "hex加密之后的密文是:" + cipherText); 
    String decrptPassword=decryptHex(cipherText); 
    System.out.println(cipherText + "hex解密之后的密码是:" + decrptPassword); 
    String cipherText_base64 = encrytBase64(password); 
    System.out.println(password + "base64加密之后的密文是:" + cipherText_base64); 
    String decrptPassword_base64=decryptBase64(cipherText_base64); 
    System.out.println(cipherText_base64 + "base64解密之后的密码是:" + decrptPassword_base64); 
    String h64=  H64.encodeToString(password.getBytes()); 
    System.out.println(h64); 
    String salt="7road"; 
    String cipherText_md5= new Md5Hash(password,salt,4).toHex(); 
    System.out.println(password+"通过md5加密之后的密文是:"+cipherText_md5); 
    System.out.println(generateKey()); 
    System.out.println("=========================================================="); 
    AesCipherService aesCipherService=new AesCipherService(); 
    aesCipherService.setKeySize(128); 
    Key key=aesCipherService.generateNewKey(); 
    String aes_cipherText= aesCipherService.encrypt(password.getBytes(),key.getEncoded()).toHex(); 
    System.out.println(password+" aes加密的密文是:"+aes_cipherText); 
    String aes_mingwen=new String(aesCipherService.decrypt(Hex.decode(aes_cipherText),key.getEncoded()).getBytes()); 
    System.out.println(aes_cipherText+" aes解密的明文是:"+aes_mingwen); 
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:26,代码来源:EndecryptUtils.java

示例4: put

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@Override
public V put(K key, V value) throws CacheException {
  logger.debug("put(K key, V value) to redis:key [" + key + "]");
  try {
    this.redisManager.set(getByteKey(key), SerializeUtils.serialize(value));

    {
      String preKey;
      if (key instanceof String) {
        preKey = (String) key;
      } else {
        preKey = key.getClass().getName() + ":" + (new Md5Hash(SerializeUtils.serialize(key))).toHex();
      }
      this.redisManager.sadd(all_caches_Key, preKey);
    }

    return value;
  } catch (Throwable t) {
    throw new CacheException(t);
  }
}
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:22,代码来源:RedisCache.java

示例5: remove

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@Override
public V remove(K key) throws CacheException {
  logger.debug("remove(K key) from redis: key [" + key + "]");
  try {
    V previous = this.get(key);

    this.redisManager.del(getByteKey(key));

    {
      String preKey;
      if (key instanceof String) {
        preKey = (String) key;
      } else {
        preKey = key.getClass().getName() + ":" + (new Md5Hash(SerializeUtils.serialize(key))).toHex();
      }
      this.redisManager.srem(all_caches_Key, preKey);
    }

    return previous;
  } catch (Throwable t) {
    throw new CacheException(t);
  }
}
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:24,代码来源:RedisCache.java

示例6: addUser

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
public int addUser(String email, String nickname, String password, long registerTime) {
    UserEntity userEntity = new UserEntity();
    userEntity.setEmail(email);
    userEntity.setNickname(nickname);
    userEntity.setPassword(new Md5Hash(password).toString());
    userEntity.setPermission(new JSONArray());
    userEntity.setRegisterTime(registerTime);

    boolean result = userDao.addUser(sqlSession, userEntity);
    return result ? userEntity.getUid() : 0;
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:12,代码来源:UserService.java

示例7: md5

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@Test
public void md5() {

    Md5Hash md5Hash = new Md5Hash("admin");
    System.out.println(md5Hash.toString());
    System.out.println(md5Hash.toHex());
    System.out.println(md5Hash.toBase64());

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:10,代码来源:ShiroTest.java

示例8: passwdMD5

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * 注册时对用户的密码进行加密
 * @param passwd 明文密码
 * @return 经过MD5加密后的密码
 */
public static String passwdMD5(String passwd){
	String saltSource = SysConst.SALTSOURCE;
	String algorithmName = "MD5";
	String credentials = passwd;
	Object salt = new Md5Hash(saltSource);
	int hashIterations = 1024;
	Object result = new SimpleHash(algorithmName, credentials, salt, hashIterations);
	return result.toString();
}
 
开发者ID:MarchMachao,项目名称:ZHFS-WEB,代码行数:15,代码来源:ShiroUtils.java

示例9: doGetAuthenticationInfo

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * 登录验证
 * 
 * @param token
 *            用户登录时的账号密码组成的token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	Object principal = token.getPrincipal();
	String accountNumber = token.getPrincipal().toString();
	String credentials = userService.getUserByAccountNumber(accountNumber).getPassword();// 根据登录accountNumber去数据库中查找密码
	String realmName = getName();
	String source = SysConst.SALTSOURCE;
	ByteSource credentialsSalt = new Md5Hash(source);
	// 密码比对过程由shiro自己完成
	SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(principal, credentials, credentialsSalt,
			realmName);
	return info;
}
 
开发者ID:MarchMachao,项目名称:ZHFS-WEB,代码行数:22,代码来源:MyRealm.java

示例10: md5Password

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/** 
 * 对密码进行md5加密,并返回密文和salt,包含在User对象中 
 * @param username 用户名 
 * @param password 密码
 * @param hashIterations 迭代次数 
 * @return UserEntity对象,包含密文和salt 
 */ 
public static UserEntity md5Password(String username,String password,int hashIterations){ 
    SecureRandomNumberGenerator secureRandomNumberGenerator=new SecureRandomNumberGenerator(); 
    String salt= secureRandomNumberGenerator.nextBytes().toHex(); 
    //组合username,两次迭代,对密码进行加密 
    String password_cryto = new Md5Hash(password,username+salt,hashIterations).toBase64(); 
    UserEntity user=new UserEntity(); 
    user.setPassword(password_cryto); 
    user.setCredentialsSalt(salt); 
    user.setUserName(username); 
    return user; 
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:19,代码来源:EndecryptUtils.java

示例11: createUser

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
@POST
public Response createUser(String body, @Context GraphDatabaseService db) throws IOException {
    HashMap parameters = UserValidator.validate(body);
    Map<String, Object> results;
    try (Transaction tx = db.beginTx()) {
        Node user = db.findNode(Labels.User, USERNAME, parameters.get(USERNAME));
        if (user == null) {
            user = db.findNode(Labels.User, EMAIL, parameters.get(EMAIL));
            if (user == null) {
                user = db.createNode(Labels.User);
                user.setProperty(EMAIL, parameters.get(EMAIL));
                user.setProperty(NAME, parameters.get(NAME));
                user.setProperty(USERNAME, parameters.get(USERNAME));
                user.setProperty(PASSWORD, parameters.get(PASSWORD));
                user.setProperty(HASH, new Md5Hash(((String)parameters.get(EMAIL)).toLowerCase()).toString());

                LocalDateTime dateTime = LocalDateTime.now(utc);
                user.setProperty(TIME, dateTime.truncatedTo(ChronoUnit.DAYS).toEpochSecond(ZoneOffset.UTC));

                results = user.getAllProperties();
            } else {
                throw UserExceptions.existingEmailParameter;
            }
        } else {
            throw UserExceptions.existingUsernameParameter;
        }
        tx.success();
    }
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:31,代码来源:Users.java

示例12: md5

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * 指定加密盐
 * @param str
 * @param salt
 * @return
 */
public static String md5(String str, String salt){
  if (StringUtil.isNullOrEmpty(salt)) {
    salt = DEFAULT_SALT;
  }
  return new Md5Hash(str,salt).toString() ;
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:13,代码来源:MD5Util.java

示例13: newUser

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * 新增用户(注册页面提交)
 */
public void newUser() {
	try {
		String username = getPara("username");
		String password = getPara("password");
		String english_name = getPara("english_name");
		User user = getModel(User.class);
		password = new Md5Hash(password).toHex();
		user.set("time", new Date());
		// 新用户默认等级-初来咋到
		user.set("level", "小学生");
		// 默认积分=0
		user.set("point", 0);
		user.set("username", username);
		user.set("english_name", english_name);
		user.set("password", password);
		user.save();
		AuthenticationToken token = new UsernamePasswordToken(username, password);
		Subject currentUser = SecurityUtils.getSubject();
		User user2 = null;
		currentUser.login(token);
		Principal principal = (Principal) currentUser.getPrincipal();
		user2 = User.dao.findById(principal.getId());
		setSessionAttr("currentUser", user2);
		setAttr("user", user);
	} catch (Exception e) {
		//失败跳到注册页面重新注册
		redirect("/user/newUser");
	}

	//成功跳到我的资料页面
	redirect("/home");
}
 
开发者ID:yaokwok,项目名称:loveabc,代码行数:36,代码来源:UserController.java

示例14: updatepwd

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * 更新密码 需判断
 */
public void updatepwd() {
	User user = User.dao.findById(getParaToInt("user.id"));
	User currentUser = getUser();
	String pwd = user.get("password");
	String rawpwd = getPara("rawpassword");
	rawpwd = new Md5Hash(rawpwd).toHex();
	if (rawpwd.equals(pwd)) {
		if (pwd == null) {
			setAttr("user", user);
			setAttr("page", 10);
			setAttr("fail", "新密码不能为空");
			render("editpwd.jsp");
		} else {
			String newpwd = new Md5Hash(getPara("user.password")).toHex();
			/*if (currentUser.isSuperAdmin() || currentUser.isAdmin()
					&& currentUser.getInt("id") != user.getInt("id")) {
				user.set("password", newpwd).update();
				redirect("/user");
			} else*/if ((currentUser.getInt("id").equals(user.getInt("id")))) {
				setAttr("success", "操作成功.请牢记密码!");
				setAttr("user", user);
				setAttr("page", 10);
				user.set("password", newpwd).update();
				render("editpwd.jsp");
			} else {
				renderError(404);
			}
		}
	} else {
		setAttr("user", user);
		setAttr("page", 10);
		setAttr("fail", "原始密码不正确,请重新输入");
		render("editpwd.jsp");
	}
}
 
开发者ID:yaokwok,项目名称:loveabc,代码行数:39,代码来源:UserController.java

示例15: getByteKey

import org.apache.shiro.crypto.hash.Md5Hash; //导入依赖的package包/类
/**
 * ���byte[]�͵�key
 * 
 * @param key
 * @return
 */
private byte[] getByteKey(K key) {
  if (key instanceof String) {
    return (this.keyPrefix + key).getBytes();
  } else {
    return (this.keyPrefix + key.getClass().getName() + ":" + (new Md5Hash(SerializeUtils.serialize(key))).toHex()).getBytes();
  }
}
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:14,代码来源:RedisCache.java


注:本文中的org.apache.shiro.crypto.hash.Md5Hash类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。