Java Code Examples for org.apache.commons.codec.digest.Md5Crypt#md5Crypt()

The following examples show how to use org.apache.commons.codec.digest.Md5Crypt#md5Crypt() . 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: DefaultCacheManager.java    From FATE-Serving with Apache License 2.0 6 votes vote down vote up
private String generateRemoteModelInferenceResultCacheKey(FederatedParams  federatedParams){
    Preconditions.checkNotNull(federatedParams);
    Preconditions.checkNotNull(federatedParams.getModelInfo());
    Preconditions.checkNotNull(federatedParams.getFeatureIdMap());
    String namespace = federatedParams.getModelInfo().getNamespace();
    String name = federatedParams.getModelInfo().getName();

    Map  sortedMap = Maps.newTreeMap();
    federatedParams.getFeatureIdMap().forEach((k,v)->{
        sortedMap.put(k,v);
    });
    StringBuffer sb  =  new StringBuffer();
    sb.append(namespace);
    sb.append(name);
    sortedMap.forEach((k,v)->{
        sb.append(k).append(v);
    });
    String md5key = Md5Crypt.md5Crypt(sb.toString().getBytes(), Dict.MD5_SALT);
    return  md5key;
}
 
Example 2
Source File: PasswordEncrypt.java    From sftpserver with Apache License 2.0 5 votes vote down vote up
public PasswordEncrypt(final String key) {
	final byte[] keyBytes = key.getBytes(US_ASCII);
	this.md5 = Md5Crypt.md5Crypt(keyBytes.clone());
	this.apr1 = Md5Crypt.apr1Crypt(keyBytes.clone());
	this.sha256 = Sha2Crypt.sha256Crypt(keyBytes.clone());
	this.sha512 = Sha2Crypt.sha512Crypt(keyBytes.clone());
	Arrays.fill(keyBytes, (byte) 0);
}
 
Example 3
Source File: PasswordEncrypt.java    From sftpserver with Apache License 2.0 5 votes vote down vote up
public static boolean checkPassword(final String crypted, final String key) {
	String crypted2 = null;
	if (crypted == null)
		return false;
	if (crypted.length() < 24)
		return false;
	if (crypted.charAt(0) != '$')
		return false;
	final int offset2ndDolar = crypted.indexOf('$', 1);
	if (offset2ndDolar < 0)
		return false;
	final int offset3ndDolar = crypted.indexOf('$', offset2ndDolar + 1);
	if (offset3ndDolar < 0)
		return false;
	final String salt = crypted.substring(0, offset3ndDolar + 1);
	final byte[] keyBytes = key.getBytes(US_ASCII);
	if (crypted.startsWith("$1$")) { // MD5
		crypted2 = Md5Crypt.md5Crypt(keyBytes.clone(), salt);
	} else if (crypted.startsWith("$apr1$")) { // APR1
		crypted2 = Md5Crypt.apr1Crypt(keyBytes.clone(), salt);
	} else if (crypted.startsWith("$5$")) { // SHA2-256
		crypted2 = Sha2Crypt.sha256Crypt(keyBytes.clone(), salt);
	} else if (crypted.startsWith("$6$")) { // SHA2-512
		crypted2 = Sha2Crypt.sha512Crypt(keyBytes.clone(), salt);
	}
	Arrays.fill(keyBytes, (byte) 0);
	if (crypted2 == null)
		return false;
	return crypted.equals(crypted2);
}
 
Example 4
Source File: UserServiceImpl.java    From unimall with Apache License 2.0 4 votes vote down vote up
@Override
@Transactional
public UserDTO login(String phone, String password, Integer loginType, String raw, String ip) throws ServiceException {
    String cryptPassword = Md5Crypt.md5Crypt(password.getBytes(), "$1$" + phone.substring(0, 7));
    UserDTO userDTO = userMapper.login(phone, cryptPassword);
    if (userDTO == null) {
        throw new AppServiceException(ExceptionDefinition.USER_PHONE_OR_PASSWORD_NOT_CORRECT);
    }
    //检查帐号是否已经冻结
    if (userDTO.getStatus() == 0) {
        throw new AppServiceException(ExceptionDefinition.USER_CAN_NOT_ACTICE);
    }
    if (!StringUtils.isEmpty(raw) && UserLoginType.contains(loginType)) {
        if (loginType == UserLoginType.MP_WEIXIN.getCode()) {
            try {
                JSONObject thirdPartJsonObject = JSONObject.parseObject(raw);
                String code = thirdPartJsonObject.getString("code");
                String body = okHttpClient.newCall(new Request.Builder()
                        .url("https://api.weixin.qq.com/sns/jscode2session?appid=" + (UserLoginType.MP_WEIXIN.getCode() == loginType ? wxMiNiAppid : wxAppAppid) +
                                "&secret=" + (UserLoginType.MP_WEIXIN.getCode() == loginType ? wxMiNiSecret : wxAppSecret) +
                                "&grant_type=authorization_code&js_code=" + code).get().build()).execute().body().string();
                JSONObject jsonObject = JSONObject.parseObject(body);
                Integer errcode = jsonObject.getInteger("errcode");
                if (errcode == null || errcode == 0) {
                    String miniOpenId = jsonObject.getString("openid");
                    //将此次登录的openId,暂且放入user的域里面,支付的时候会用到
                    userDTO.setLoginType(loginType);
                    userDTO.setOpenId(miniOpenId);
                }
            } catch (Exception e) {
                logger.error("[微信第三方登录] 异常", e);
                throw new ThirdPartServiceException(ExceptionDefinition.THIRD_PART_SERVICE_EXCEPTION.getMsg(), ExceptionDefinition.THIRD_PART_SERVICE_EXCEPTION.getCode());
            }
        }
    }
    String accessToken = GeneratorUtil.genSessionId();
    //放入SESSION专用Redis数据源中
    userRedisTemplate.opsForValue().set(Const.USER_REDIS_PREFIX + accessToken, JSONObject.toJSONString(userDTO));
    userDTO.setAccessToken(accessToken);
    UserDO userUpdateDO = new UserDO();
    userUpdateDO.setId(userDTO.getId());
    userUpdateDO.setGmtLastLogin(new Date());
    userUpdateDO.setLastLoginIp(ip);
    userMapper.updateById(userUpdateDO);
    return userDTO;
}
 
Example 5
Source File: ModelService.java    From FATE-Serving with Apache License 2.0 4 votes vote down vote up
private String md5Crypt(PublishRequest req) {
    char[] encryptArray = StringUtils.join(req.getLocal(), req.getRoleMap(), req.getModelMap()).toCharArray();
    Arrays.sort(encryptArray);
    String key = Md5Crypt.md5Crypt(String.valueOf(encryptArray).getBytes(), Dict.MD5_SALT);
    return key;
}
 
Example 6
Source File: Md5CryptUtil.java    From Photo with GNU General Public License v3.0 4 votes vote down vote up
public static String EncryptPassword(String password,String salt){
 final String MAGICPREFIX="$1$";
 return Md5Crypt.md5Crypt(password.getBytes(),MAGICPREFIX+salt);
}