Java Code Examples for com.jeesuite.common.util.DigestUtils

The following examples show how to use com.jeesuite.common.util.DigestUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jeesuite-libs   Source File: MybatisTest.java    License: Apache License 2.0 6 votes vote down vote up
private void insertTestData(){
	
	for (int i = 0; i < mobiles.length; i++) {
		UserEntity entity = new UserEntity();
		entity.setCreatedAt(new Date());
		entity.setEmail(mobiles[i] + "@163.com");
		entity.setMobile(mobiles[i]);
		entity.setType((short)(i % 2 == 0 ? 1 : 2));
		entity.setStatus((short)(i % 3 == 0 ? 1 : 2));
		userMapper.insert(entity);
		
		SnsAccounyBindingEntity bindingEntity = new SnsAccounyBindingEntity();
		bindingEntity.setUserId(entity.getId());
		bindingEntity.setUnionId(DigestUtils.md5(mobiles[i] ));
		bindingEntity.setSnsType("weixin");
		bindingEntity.setEnabled(true);
		snsAccounyBindingMapper.insertSelective(bindingEntity);
	}
}
 
Example 2
Source Project: jeesuite-libs   Source File: MybatisTest.java    License: Apache License 2.0 6 votes vote down vote up
private void initCache() {
	UserEntity entity = userMapper.findByMobile(mobiles[0]);
	userMapper.findByMobile(mobiles[1]);
	userMapper.findByLoginName(mobiles[0]+"@163.com");
	userMapper.findByLoginName(mobiles[1]+"@163.com");
	userMapper.findByWxUnionId(DigestUtils.md5(mobiles[3] ));
	userMapper.findByStatus((short) 1);
	userMapper.findByStatus((short) 2);
	userMapper.findByType((short) 1);
	userMapper.findWxUnionIdByUserId(entity.getId());

	// 生成的缓存key为:UserEntity.findByStatus:2
	EntityCacheHelper.queryTryCache(UserEntity.class, "findByStatus:2", new Callable<List<UserEntity>>() {
		public List<UserEntity> call() throws Exception {
			// 查询语句
			List<UserEntity> entitys = userMapper.findByStatus((short) 2);
			return entitys;
		}
	});
	userMapper.countByType(1);
}
 
Example 3
Source Project: oneplatform   Source File: AccountEntity.java    License: Apache License 2.0 5 votes vote down vote up
public static String encryptPassword(String password) {
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < password.length(); i++) {
		sb.append(password.charAt(i)).append(salts.substring(i*2, (i+1)*2));
	}
	return DigestUtils.md5(sb.toString());

}
 
Example 4
Source Project: jeesuite-config   Source File: ConfigcenterContext.java    License: Apache License 2.0 5 votes vote down vote up
private static String decryptWithAES(String key, String data){
	try {
		String secretKey = DigestUtils.md5(key).substring(16);
		byte[] bytes = AES.decrypt(Base64.decode(data.getBytes(StandardCharsets.UTF_8)),  secretKey.getBytes(StandardCharsets.UTF_8));
		return  new String(bytes, StandardCharsets.UTF_8);
	} catch (Exception e) {
		System.err.println(String.format("解密错误:%s",data));
		throw new RuntimeException(e);
	}
}
 
Example 5
Source Project: jeesuite-config   Source File: UserEntity.java    License: Apache License 2.0 5 votes vote down vote up
public static String encryptPassword(String password) {
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < password.length(); i++) {
		sb.append(password.charAt(i)).append(salts.substring(i*2, (i+1)*2));
	}
	return DigestUtils.md5(sb.toString());

}
 
Example 6
Source Project: jeesuite-config   Source File: CryptComponent.java    License: Apache License 2.0 5 votes vote down vote up
private static String encryptWithAES(String key, String data){
	try {
		String secretKey = DigestUtils.md5(key).substring(16);
		byte[] bytes = AES.encrypt(data.getBytes(StandardCharsets.UTF_8), secretKey.getBytes(StandardCharsets.UTF_8));
		return  Base64.encodeToString(bytes, false);
	} catch (Exception e) {
		throw new JeesuiteBaseException(9999, "加密失败");
	}
}
 
Example 7
Source Project: jeesuite-config   Source File: CryptComponent.java    License: Apache License 2.0 5 votes vote down vote up
private static String decryptWithAES(String key, String data){
	try {
		String secretKey = DigestUtils.md5(key).substring(16);
		byte[] bytes = AES.decrypt(Base64.decode(data.getBytes(StandardCharsets.UTF_8)),  secretKey.getBytes(StandardCharsets.UTF_8));
		return  new String(bytes, StandardCharsets.UTF_8);
	} catch (Exception e) {
		throw new JeesuiteBaseException(9999, "解密失败");
	}
}
 
Example 8
Source Project: jeesuite-libs   Source File: CacheHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 生成查询缓存key
 * @param cacheInfo
 * @param param
 * @return
 */
@SuppressWarnings("unchecked")
private String genarateQueryCacheKey(String keyPattern,Object param){
	String text;
	try {
		Object[] args;
		if(param instanceof Map){
			Map<String, Object> map = (Map<String, Object>) param;
			if(map.containsKey(STR_PARAM + "1")){
				args = new String[map.size()/2];
				for (int i = 0; i < args.length; i++) {
					args[i] = CacheKeyUtils.objcetToString(map.get(STR_PARAM + (i+1)));
				}
			}else{
				args = new String[]{CacheKeyUtils.objcetToString(map)};
			}
		}else if(param instanceof BaseEntity){
			Serializable id = ((BaseEntity)param).getId();
			if(id != null && !"0".equals(id.toString())){	
				args = new String[]{(((BaseEntity)param).getId()).toString()};
			}else{
				args = new String[]{CacheKeyUtils.objcetToString(param)};
			}
		}else if(param instanceof Object[]){
			args = (Object[])param;
		}else if(param == null){
			args = new Object[0];
		}else{
			args = new String[]{CacheKeyUtils.objcetToString(param)};
		}
		
		text = StringUtils.join(args,"-");
	} catch (Exception e) {
		text = JsonUtils.toJson(param);
		e.printStackTrace();
	}
	if(text.length() > 64)text = DigestUtils.md5(text);

	return String.format(keyPattern, text);
}
 
Example 9
Source Project: oneplatform   Source File: SecurityCryptUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String generateAuthCode(){
	String str = DigestUtils.md5Short(TokenGenerator.generate()).concat(String.valueOf(System.currentTimeMillis()));	
	return SecurityCryptUtils.encrypt(str);
}
 
Example 10
Source Project: jeesuite-config   Source File: CryptComponent.java    License: Apache License 2.0 4 votes vote down vote up
public String getCryptKey(int appId,String env){
	String base = secretKey + Integer.toHexString(appId).concat(env);
	return DigestUtils.md5(base);
}