本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}