本文整理汇总了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;
}
示例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));
}
示例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;
}
示例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());
}
示例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: 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;
}
示例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());
}
示例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;
}
}
示例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()));
}
示例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());
}
示例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;
}
}
示例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();
}
示例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", "注册失败. 请校验数据后请再提交数据");
}
示例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);
}