Java Code Examples for org.springframework.util.DigestUtils#md5DigestAsHex()

The following examples show how to use org.springframework.util.DigestUtils#md5DigestAsHex() . 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 File: AdminServiceImpl.java    From notes with Apache License 2.0 6 votes vote down vote up
@Override
public AdminDto addAdmin(AdminDto dto) throws CommonException {

    String password = StringUtils.trimToEmpty(dto.getAdminPassword());
    if (EMPTY.equals(password)){
        throw new CommonException(ERROR_REGISTRYPASSWORD100011);
    }

    String name = StringUtils.trimToEmpty(dto.getAdminName());
    if (EMPTY.equals(name)){
        throw new CommonException(ERROR_REGISTRY_ADMIN_NAME100012);
    }

    String salt = RandomStringUtils.randomNumeric(6);
    dto.setAdminSalt(salt);
    String md5Password = DigestUtils.md5DigestAsHex((password + salt).getBytes());
    dto.setAdminPassword(md5Password);
    int adminId = adminDtoMapper.insert(dto);
    dto.setAdminId(Long.parseLong(String.valueOf(adminId)));
    dto.setAdminSalt(null);
    return dto;
}
 
Example 2
Source File: RegisterServiceImpl.java    From Movie_Recommend with MIT License 6 votes vote down vote up
@Override
public E3Result register(User user) {
    // 数据有效性校验
    if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())|| StringUtils.isBlank(user.getEmail())) {
        return E3Result.build(400, "用户数据不完整,注册失败");
    }
    // 补全pojo的属性
    user.setRegistertime(new Date());
    user.setLastlogintime(new Date());
    // 对密码进行md5加密
    String md5Pass = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
    user.setPassword(md5Pass);
    // 把用户数据插入到数据库中
    userMapper.insert(user);//新增3.18
    Integer userId = user.getUserid();
    // 返回添加成功
    return E3Result.ok(userId);
}
 
Example 3
Source File: UserController.java    From xxl-conf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * add
 *
 * @return
 */
@RequestMapping("/add")
@PermessionLimit(adminuser = true)
@ResponseBody
public ReturnT<String> add(XxlConfUser xxlConfUser){

    // valid
    if (StringUtils.isBlank(xxlConfUser.getUsername())){
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "用户名不可为空");
    }
    if (StringUtils.isBlank(xxlConfUser.getPassword())){
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码不可为空");
    }
    if (!(xxlConfUser.getPassword().length()>=4 && xxlConfUser.getPassword().length()<=100)) {
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码长度限制为4~50");
    }

    // passowrd md5
    String md5Password = DigestUtils.md5DigestAsHex(xxlConfUser.getPassword().getBytes());
    xxlConfUser.setPassword(md5Password);

    int ret = xxlConfUserDao.add(xxlConfUser);
    return ret>0? ReturnT.SUCCESS: ReturnT.FAIL;
}
 
Example 4
Source File: RegisterServiceImpl.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int register(String userName,String userPwd) {

	TbMember tbMember=new TbMember();
	tbMember.setUsername(userName);

	if(userName.isEmpty()||userPwd.isEmpty()){
		return -1; //用户名密码不能为空
	}
	boolean result = checkData(userName, 1);
	if (!result) {
		return 0; //该用户名已被注册
	}

	//MD5加密
	String md5Pass = DigestUtils.md5DigestAsHex(userPwd.getBytes());
	tbMember.setPassword(md5Pass);
	tbMember.setState(1);
	tbMember.setCreated(new Date());
	tbMember.setUpdated(new Date());

	if(tbMemberMapper.insert(tbMember)!=1){
		throw new XmallException("注册用户失败");
	}
	return 1;
}
 
Example 5
Source File: PermissionInterceptor.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
public static boolean login(HttpServletResponse response, String username, String password, boolean ifRemember){

    	// login token
		String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes());
		tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);

		if (!getLoginIdentityToken().equals(tokenTmp)){
			return false;
		}

		// do login
		CookieUtil.set(response, LOGIN_IDENTITY_KEY, getLoginIdentityToken(), ifRemember);
		return true;
	}
 
Example 6
Source File: ContentBasedVersionStrategyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getResourceVersion() throws Exception {
	Resource expected = new ClassPathResource("test/bar.css", getClass());
	String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream()));

	assertEquals(hash, this.strategy.getResourceVersion(expected).block());
}
 
Example 7
Source File: PermissionInterceptor.java    From xxl-rpc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {

    // valid
    if (username==null || username.trim().length()==0 || password==null || password.trim().length()==0) {
        throw new RuntimeException("权限账号密码不可为空");
    }

    // login token
    String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes());		//.getBytes("UTF-8")
    tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);

    LOGIN_IDENTITY_TOKEN = tokenTmp;
}
 
Example 8
Source File: MyStringUtils.java    From EosProxyServer with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取指定内容的md5值,暂时不加盐
 * @param source
 * @return
 */
public static String getMD5(String source) {
	if (source==null) {
		return null;
	}
	String MD5 = DigestUtils.md5DigestAsHex(source.getBytes());
	return MD5;
}
 
Example 9
Source File: CheckSum.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public static CheckSum compute(int version, String value) {
    if (version == 0) {
        byte[] bValue = value.getBytes(Charset.forName("UTF-8"));
        return new CheckSum(version, DigestUtils.md5DigestAsHex(bValue));
    }
    throw new IllegalArgumentException("Unsupported check sum version : " + version);
}
 
Example 10
Source File: ContentVersionStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public String getResourceVersion(Resource resource) {
	try {
		byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
		return DigestUtils.md5DigestAsHex(content);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Failed to calculate hash for " + resource, ex);
	}
}
 
Example 11
Source File: ContentVersionStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public String getResourceVersion(Resource resource) {
	try {
		byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
		return DigestUtils.md5DigestAsHex(content);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Failed to calculate hash for " + resource, ex);
	}
}
 
Example 12
Source File: ArcusCache.java    From arcus-spring with Apache License 2.0 5 votes vote down vote up
/**
 * serviceId, prefix, name 값을 사용하여 아커스 키를 생성합니다. serviceId는 필수값이며, prefix 또는
 * name 둘 중에 하나가 반드시 있어야 합니다. name과 prefix값이 모두 있다면 prefix 값을 사용합니다.
 * <p>
 * 키 생성 로직은 다음과 같습니다.
 * <p>
 * serviceId + (prefix | name) + ":" + key.toString();
 * <p>
 * 만약 전체 키의 길이가 250자를 넘을 경우에는 key.toString() 대신 그 값을 MD5로 압축한 값을 사용합니다.
 *
 * @param key
 * @return
 */
public String createArcusKey(final Object key) {
  Assert.notNull(key);
  String keyString, arcusKey;

  if (key instanceof ArcusStringKey) {
    keyString = ((ArcusStringKey) key).getStringKey().replace(' ', '_') +
            String.valueOf(((ArcusStringKey) key).getHash());
  } else if (key instanceof Integer) {
    keyString = key.toString();
  } else {
    keyString = key.toString();
    int hash = ArcusStringKey.light_hash(keyString);
    keyString = keyString.replace(' ', '_') + String.valueOf(hash);
  }

  arcusKey = serviceId + name + ":" + keyString;
  if (this.prefix != null) {
    arcusKey = serviceId + prefix + ":" + keyString;
  }
  if (arcusKey.length() > 250) {
    String digestedString = DigestUtils.md5DigestAsHex(keyString
            .getBytes());
    arcusKey = serviceId + name + ":" + digestedString;
    if (this.prefix != null) {
      arcusKey = serviceId + prefix + ":" + digestedString;
    }
  }
  return arcusKey;
}
 
Example 13
Source File: SignatureInfo.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * 默认的签名验证方法
 *
 * sign = md5(nonce + timestamp + base64(param))
 *
 * @return true or false
 */
Boolean checkSignature(){
    String origin = this.nonce + this.timestamp;
    if(StringUtils.isNotBlank(this.params)){
        origin = origin + Base64.getEncoder().encodeToString(this.params.getBytes(Charset.forName("utf-8")));
    }
    String signature = DigestUtils.md5DigestAsHex(origin.getBytes(Charset.forName("utf-8")));
    return signature.equals(this.sign);
}
 
Example 14
Source File: MD5Util.java    From star-zone with Apache License 2.0 4 votes vote down vote up
public static String md5(String src) {
	return DigestUtils.md5DigestAsHex(src.getBytes());
}
 
Example 15
Source File: AppCacheManifestTransformer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public TransformedResource createResource() {
	String hash = DigestUtils.md5DigestAsHex(this.baos.toByteArray());
	this.writer.write("\n" + "# Hash: " + hash);
	byte[] bytes = this.writer.toString().getBytes(DEFAULT_CHARSET);
	return new TransformedResource(this.resource, bytes);
}
 
Example 16
Source File: AppCacheManifestTransformer.java    From java-technology-stack with MIT License 4 votes vote down vote up
public TransformedResource createResource() {
	String hash = DigestUtils.md5DigestAsHex(this.baos.toByteArray());
	this.writer.write("\n" + "# Hash: " + hash);
	byte[] bytes = this.writer.toString().getBytes(DEFAULT_CHARSET);
	return new TransformedResource(this.resource, bytes);
}
 
Example 17
Source File: PosterConfig.java    From poster-generater with MIT License 4 votes vote down vote up
public String url2fileName(String url) {
    return DigestUtils.md5DigestAsHex(url.getBytes()) + ".png";
}
 
Example 18
Source File: User.java    From wallride with Apache License 2.0 4 votes vote down vote up
public String getGravatarUrl(int size) throws UnsupportedEncodingException {
	String hash = DigestUtils.md5DigestAsHex(getEmail().getBytes("CP1252"));
	return String.format("https://secure.gravatar.com/avatar/%s?size=%d&d=mm", hash, size);
}
 
Example 19
Source File: AppCacheManifestTransformer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public String build() {
	return DigestUtils.md5DigestAsHex(this.baos.toByteArray());
}
 
Example 20
Source File: MD5Utils.java    From jeesupport with MIT License 2 votes vote down vote up
/**
 * 无私钥MD5加密
 * 
 * @param _txt
 *            待加密内容
 * @return 加密结果
 */
public static String s_encode( String _txt ) {
	return DigestUtils.md5DigestAsHex( _txt.getBytes() );
}