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


Java DigestUtils.md5DigestAsHex方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例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: 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

示例8: 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

示例9: 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

示例10: store

import org.springframework.util.DigestUtils; //导入方法依赖的package包/类
/**
 * 如果图片的大小大于1M,那么进行等比压缩为1280x1280图片
 * @param file
 * @return
 * @throws Exception
 */
public Storage store(MultipartFile file) throws Exception {

    if (file.isEmpty()) {
        throw new Exception("Failed to store empty file " + file.getOriginalFilename());
    }

    String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
    byte[] bytes;
    // 如果原图片大于1M, 那么压缩图片
    if (file.getSize() > M) {
        bytes = ImageUtil.compress(file.getInputStream(), fileType, 1920, 1920);
    } else {
        bytes = file.getBytes();
    }

    String contentHash = DigestUtils.md5DigestAsHex(bytes);
    Storage oldStorage = storageRepository.findByFileHash(contentHash);
    if (oldStorage != null) return oldStorage;

    try {
        Path destDir = Paths.get(storageDirectory, contentHash.substring(0, 2));
        if (!Files.exists(destDir)) Files.createDirectory(destDir);

        // String filePath = contentHash.substring(0, 2) + "/" + contentHash.substring(2) + "." + fileType;
        Storage storage = new Storage();
        storage.setFileHash(contentHash);
        storage.setFileName(file.getName());
        storage.setFileType(file.getContentType());
        storage.setFileSize(file.getSize());
        storage.setOriginalFileName(file.getOriginalFilename());

        return storageRepository.save(storage);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

}
 
开发者ID:myliang,项目名称:fish-admin,代码行数:45,代码来源:StorageService.java

示例11: changePassword

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

    TbUser old=tbUserMapper.selectByPrimaryKey(tbUser.getId());
    old.setUpdated(new Date());
    String md5Pass = DigestUtils.md5DigestAsHex(tbUser.getPassword().getBytes());
    old.setPassword(md5Pass);
    if(tbUserMapper.updateByPrimaryKey(old)!=1){
        throw new XmallException("修改用户密码失败");
    }
    return 1;
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:13,代码来源:UserServiceImpl.java

示例12: getMd5Url

import org.springframework.util.DigestUtils; //导入方法依赖的package包/类
private String getMd5Url(Long id) throws UnsupportedEncodingException {
    String cacheKey = CacheKeyGenerator.generate(String.class, "getMd5Url", id);
    // 先从缓存中取
    String md5Url = byteRedisClient.getByteObj(cacheKey, String.class);
    if (StringUtils.isBlank(md5Url)) {
        String saltUrl = id + "/" + Instant.now().toEpochMilli() + "/" + appProperties.getPrivateSalt();
        md5Url = DigestUtils.md5DigestAsHex(saltUrl.getBytes(AppConstants.CHARSET_UTF8));
        byteRedisClient.setByteObj(cacheKey, md5Url, 3600);
    }
    return md5Url;
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:12,代码来源:SpecialServiceImpl.java

示例13: savePatch

import org.springframework.util.DigestUtils; //导入方法依赖的package包/类
public PatchInfo savePatch(AppInfo appInfo, VersionInfo versionInfo, String description, MultipartFile multipartFile) {
    List<PatchInfo> patchInfoList = patchInfoMapper.findByUidAndVersionName(appInfo.getUid(),versionInfo.getVersionName());
    int maxPatchVersion = getMaxPatchVersion(patchInfoList) + 1;
    String childPath = appInfo.getUid() + "/" + versionInfo.getVersionName() + "/" + maxPatchVersion + "/";
    PatchInfo patchInfo = new PatchInfo();
    try {
        String fileHash = DigestUtils.md5DigestAsHex(multipartFile.getBytes());
        File path = new File(new File(fileStoragePath), childPath);
        File patchFile = new File(path,fileHash + "_patch.zip");

        if (!path.exists() && !path.mkdirs()) {
            throw new BizException("文件目录创建失败");
        }
        multipartFile.transferTo(patchFile);

        patchInfo.setUserId(appInfo.getUserId());
        patchInfo.setAppUid(appInfo.getUid());
        patchInfo.setUid(UUID.randomUUID().toString().replaceAll("-", ""));
        patchInfo.setVersionName(versionInfo.getVersionName());
        patchInfo.setPatchVersion(maxPatchVersion);
        patchInfo.setPatchSize(patchFile.length());
        patchInfo.setFileHash(fileHash);
        patchInfo.setDescription(description);
        patchInfo.setStoragePath(patchFile.getAbsolutePath());
        patchInfo.setDownloadUrl(getDownloadUrl(patchStaticUrl,childPath + patchFile.getName()));
        patchInfo.setCreatedAt(new Date());
        patchInfo.setUpdatedAt(new Date());

        Integer id = patchInfoMapper.insert(patchInfo);
        patchInfo.setId(id);
    } catch (IOException e) {
        e.printStackTrace();
        throw new BizException("文件保存失败");
    }

    facadeService.clearCache();
    return patchInfo;
}
 
开发者ID:baidao,项目名称:tinker-manager,代码行数:39,代码来源:PatchService.java

示例14: authenticate

import org.springframework.util.DigestUtils; //导入方法依赖的package包/类
public boolean authenticate(String username,String password) {
    BasicUser basicUser = findByUsername(username);
    if (basicUser == null) {
        return false;
    }
    String correctPassword = DigestUtils.md5DigestAsHex((globalSecretKey + "_" + password).getBytes());
    return basicUser.getPassword().equals(correctPassword);
}
 
开发者ID:baidao,项目名称:tinker-manager,代码行数:9,代码来源:AccountService.java

示例15: generateApiKey

import org.springframework.util.DigestUtils; //导入方法依赖的package包/类
public String generateApiKey(final SMSBridge smsBridge) {
    try {
        final String source = smsBridge.generateApiKey() ;
        return DigestUtils.md5DigestAsHex(source.getBytes("UTF-8"));
    } catch (Exception ex) {
        logger.error("Could not create API key, reason,", ex);
        throw new IllegalArgumentException(ex);
    }
}
 
开发者ID:openMF,项目名称:message-gateway,代码行数:10,代码来源:SecurityService.java


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