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


Java DigestUtils类代码示例

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


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

示例1: Login

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@ApiOperation("登录接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "email", value = "用户邮箱",dataType = "String"),
        @ApiImplicitParam(name = "password", value = "用户密码",dataType = "String")
})
@PostMapping("/login")
public QuarkResult Login(String email,String password) {

    QuarkResult result = restProcessor(() -> {
        User loginUser = userService.findByEmail(email);
        if (loginUser == null)
            return QuarkResult.warn("用户邮箱不存在,请重新输入");
        if (!loginUser.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes())))
            return QuarkResult.warn("用户密码错误,请重新输入");
        String token = userService.LoginUser(loginUser);
        return QuarkResult.ok(token);
    });
    return result;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:20,代码来源:UserController.java

示例2: shouldCreateHashForFile

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Test
public void shouldCreateHashForFile() {
  //given
  PowerMockito.mockStatic(IoUtil.class);
  PowerMockito.mockStatic(DigestUtils.class);
  byte[] bytes = new byte[]{1,2,3};
  final String fileEntry = "fileEntry";
  final ZipInputStream zipInputStream = mock(ZipInputStream.class);
  when(IoUtil.readInputStream(zipInputStream, fileEntry)).thenReturn(bytes);
  final String hash = "hash";
  when(DigestUtils.md5DigestAsHex(bytes)).thenReturn(hash);

  //when
  final String result = zipResourceService.createHashForFile(zipInputStream, fileEntry);

  //then
  assertThat(result, equalTo(hash));
}
 
开发者ID:satspeedy,项目名称:camunda-migrator,代码行数:19,代码来源:ZipResourceServiceHashTest.java

示例3: register

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@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;
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:27,代码来源:RegisterServiceImpl.java

示例4: addMember

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public TbMember addMember(MemberDto memberDto) {

    TbMember tbMember= DtoUtil.MemberDto2Member(memberDto);

    if(getMemberByUsername(tbMember.getUsername())!=null){
        throw new XmallException("用户名已被注册");
    }
    if(getMemberByPhone(tbMember.getPhone())!=null){
        throw new XmallException("手机号已被注册");
    }
    if(getMemberByEmail(tbMember.getEmail())!=null){
        throw new XmallException("邮箱已被注册");
    }

    tbMember.setState(1);
    tbMember.setCreated(new Date());
    tbMember.setUpdated(new Date());
    String md5Pass = DigestUtils.md5DigestAsHex(tbMember.getPassword().getBytes());
    tbMember.setPassword(md5Pass);

    if(tbMemberMapper.insert(tbMember)!=1){
        throw new XmallException("添加用户失败");
    }
    return getMemberByPhone(tbMember.getPhone());
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:27,代码来源:MemberServiceImpl.java

示例5: updateMember

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public TbMember updateMember(Long id,MemberDto memberDto) {

    TbMember tbMember = DtoUtil.MemberDto2Member(memberDto);
    tbMember.setId(id);
    tbMember.setUpdated(new Date());
    TbMember oldMember=getMemberById(id);
    tbMember.setState(oldMember.getState());
    tbMember.setCreated(oldMember.getCreated());
    if(tbMember.getPassword()==null||tbMember.getPassword()==""){
        tbMember.setPassword(oldMember.getPassword());
    }else{
        String md5Pass = DigestUtils.md5DigestAsHex(tbMember.getPassword().getBytes());
        tbMember.setPassword(md5Pass);
    }

    if (tbMemberMapper.updateByPrimaryKey(tbMember) != 1){
        throw new XmallException("更新会员信息失败");
    }
    return getMemberById(id);
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:22,代码来源:MemberServiceImpl.java

示例6: changePassMember

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public TbMember changePassMember(Long id, MemberDto memberDto) {

    TbMember tbMember=getMemberById(id);
    if(tbMember.getPassword()==null||tbMember.getPassword()==""){
        tbMember.setPassword(tbMember.getPassword());
    }else{
        String md5Pass = DigestUtils.md5DigestAsHex(tbMember.getPassword().getBytes());
        tbMember.setPassword(md5Pass);
    }

    if (tbMemberMapper.updateByPrimaryKey(tbMember) != 1){
        throw new XmallException("修改会员密码失败");
    }
    return getMemberById(id);
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:17,代码来源:MemberServiceImpl.java

示例7: addUser

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public int addUser(TbUser user) {

    if(!getUserByName(user.getUsername())){
        throw new XmallException("用户名已存在");
    }
    if(!getUserByPhone(user.getPhone())){
        throw new XmallException("手机号已存在");
    }
    if(!getUserByEmail(user.getEmail())){
        throw new XmallException("邮箱已存在");
    }
    String md5Pass = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
    user.setPassword(md5Pass);
    user.setState(1);
    user.setCreated(new Date());
    user.setUpdated(new Date());
    if(tbUserMapper.insert(user)!=1){
        throw new XmallException("添加用户失败");
    }
    return 1;
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:23,代码来源:UserServiceImpl.java

示例8: getToken

import org.springframework.util.DigestUtils; //导入依赖的package包/类
/**
 * 获取令牌
 * 
 * @return 令牌
 */
@Transient
public String getToken() {
	HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(17, 37).append(getKey());
	if (getCartItems() != null) {
		for (CartItem cartItem : getCartItems()) {
			hashCodeBuilder.append(cartItem.getProduct()).append(cartItem.getQuantity())
					.append(cartItem.getPrice());
		}
	}
	return DigestUtils.md5DigestAsHex(hashCodeBuilder.toString().getBytes());
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:17,代码来源:Cart.java

示例9: beforeBodyWrite

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
    String etag = serverHttpRequest.getHeaders().getFirst(HttpHeaders.IF_NONE_MATCH);
    if (!((GET.equals(serverHttpRequest.getMethod().name())) || (HEAD.equals(serverHttpRequest.getMethod().name())))) {
        return o;
    }
    String md5;
    if (o instanceof ResponseEntity) {
        ResponseEntity response = (ResponseEntity) o;
        md5 = DigestUtils.md5DigestAsHex(JsonUtils.toJsonString(response.getBody()).getBytes());
    } else {
        md5 = DigestUtils.md5DigestAsHex(JsonUtils.toJsonString(o).getBytes());
    }
    serverHttpResponse.getHeaders().add("Etag", md5);
    if (md5.equalsIgnoreCase(etag)) {
        serverHttpResponse.setStatusCode(HttpStatus.NOT_MODIFIED);
        return null;
    } else {
        return o;
    }
}
 
开发者ID:ismartx,项目名称:summer,代码行数:22,代码来源:CacheAdvice.java

示例10: getCDNUrl

import org.springframework.util.DigestUtils; //导入依赖的package包/类
public String getCDNUrl(Image img, int size) {
	int id = Integer.parseInt(img.getIdentifier().substring(
			img.getIdentifier().lastIndexOf(':') + 1,
			img.getIdentifier().length()));

	return String.format("%s/%s.jpg",
			CDNPrefix,
			DigestUtils.md5DigestAsHex((id + "-" + size + "-" + CDNKey).getBytes()));
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:10,代码来源:CDNImageHelper.java

示例11: commence

import org.springframework.util.DigestUtils; //导入依赖的package包/类
public void commence(HttpServletRequest request,
		HttpServletResponse response, AuthenticationException authException)
		throws IOException, ServletException {
	HttpServletResponse httpResponse = (HttpServletResponse) response;

	// compute a nonce (do not use remote IP address due to proxy farms)
	// format of nonce is:
	// base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
	long expiryTime = System.currentTimeMillis()
			+ (super.getNonceValiditySeconds() * 1000);
	String signatureValue = DigestUtils.md5DigestAsHex(new String(
			expiryTime + ":" + super.getKey()).getBytes());
	String nonceValue = expiryTime + ":" + signatureValue;
	String nonceValueBase64 = new String(Base64.encode(nonceValue
			.getBytes()));

	// qop is quality of protection, as defined by RFC 2617.
	// we do not use opaque due to IE violation of RFC 2617 in not
	// representing opaque on subsequent requests in same session.
	String authenticateHeader = "DigestCustom realm=\"" + super.getRealmName()
			+ "\", " + "qop=\"auth\", nonce=\"" + nonceValueBase64 + "\"";

	if (authException instanceof NonceExpiredException) {
		authenticateHeader = authenticateHeader + ", stale=\"true\"";
	}

	if (logger.isDebugEnabled()) {
		logger.debug("WWW-Authenticate header sent to user agent: "
				+ authenticateHeader);
	}

	httpResponse.addHeader("WWW-Authenticate", authenticateHeader);
	httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED,
			authException.getMessage());
}
 
开发者ID:cadocruz,项目名称:spring-security-digest,代码行数:36,代码来源:RestDigestAuthenticationEntryPoint.java

示例12: sanitize

import org.springframework.util.DigestUtils; //导入依赖的package包/类
public static String sanitize(String uri, ConnectionSpec auth) {
    try {
        String sanitizedUserInfo = "";
        if ((auth != null) && (StringUtils.hasText(auth.toString()))) {
            if (auth instanceof AccessVerifyConnectionSpec) {
                String password = ((AccessVerifyConnectionSpec) auth).getCredentials();
                password = DigestUtils.md5DigestAsHex(password.getBytes("UTF-8"));
                String division = ((AccessVerifyConnectionSpec) auth).getDivision();
                if (StringUtils.hasText(division)) {
                    sanitizedUserInfo = division + DIVISION_CREDENTIALS_DELIMITER + password;
                } else {
                    sanitizedUserInfo = password;
                }
            }
        }
        UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uri).userInfo(sanitizedUserInfo);
        return builder.build().toString();
    } catch (UnsupportedEncodingException e) {
        // NOOP: should never happen (UTF-8 built into JVM)
        return null;
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:23,代码来源:RpcUriUtils.java

示例13: writeModel

import org.springframework.util.DigestUtils; //导入依赖的package包/类
public static void writeModel(HttpServletRequest request,
		HttpServletResponse response, ModelBean model, OutputConfig outputConfig)
		throws IOException {

	byte[] data = generateJavascript(model, outputConfig).getBytes(UTF8_CHARSET);
	String ifNoneMatch = request.getHeader("If-None-Match");
	String etag = "\"0" + DigestUtils.md5DigestAsHex(data) + "\"";

	response.setHeader("ETag", etag);

	if (etag.equals(ifNoneMatch)) {
		response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
		return;
	}

	response.setContentType("application/javascript");
	response.setCharacterEncoding(UTF8_CHARSET.name());
	response.setContentLength(data.length);

	@SuppressWarnings("resource")
	ServletOutputStream out = response.getOutputStream();
	out.write(data);
	out.flush();
}
 
开发者ID:ralscha,项目名称:extclassgenerator,代码行数:25,代码来源:ModelGenerator.java

示例14: register

import org.springframework.util.DigestUtils; //导入依赖的package包/类
/**
 * 请求格式 POST
 * 用户注册
 *
 * @param user Tbuser POJO Json
 * @return {
 *          status: 200 //200 成功 400 数据错误 500 系统异常
 *          msg: "OK" //错误 注册失败. 请校验数据后请再提交数据.
 *          data: null
 *         }
 */
@Override
public XbinResult register(TbUser user) {

    if (user == null) {
        return XbinResult.build(400, "error", "数据为空");
    }

    boolean usernameb = (boolean) checkUserDate(user.getUsername(), ERROR, null).getData();
    boolean phoneb = (boolean) checkUserDate(user.getPhone(), 2, null).getData();
    boolean emailb = (boolean) checkUserDate(user.getEmail(), 3, null).getData();

    if (usernameb & phoneb & emailb) {
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));

        user.setCreated(new Date());
        user.setUpdated(new Date());

        try {
            userMapper.insert(user);
        } catch (Exception e) {

            logger.error("保存数据库失败!注册失败", e);
            return XbinResult.build(500, "error", "系统异常. 请稍后重试");
        }
        return XbinResult.ok();
    }

    return XbinResult.build(400, "error", "注册失败. 请校验数据后请再提交数据");


}
 
开发者ID:xubinux,项目名称:xbin-store,代码行数:43,代码来源:UserServiceImpl.java

示例15: createUser

import org.springframework.util.DigestUtils; //导入依赖的package包/类
@Override
public void createUser(String email, String username, String password) {
    User user = new User();
    user.setEmail(email);
    user.setUsername(username);
    user.setInitTime(new Date());
    user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
    repository.save(user);
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:10,代码来源:UserServiceImpl.java


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