Encrypt.java 1.1 KB
package com.teplot.common;

import com.jfinal.kit.HashKit;
import com.jfinal.kit.StrKit;

/**
 * Depiction: 密码加密
 * <p>
 * Modify:
 * <p>
 * Author: Kevin Lynn
 * <p>
 * Create Date:2017年6月1日 上午12:31:18
 * 
 */
public class Encrypt {

	public static void main(String[] args) {
		System.out.println(Encrypt.encrypt("west", HashKit.sha256("000000")));
	}

	/**
	 * 
	 * @param username
	 *            用户名
	 * @param password
	 *            对密码原串sha256之后的密文
	 * @return
	 */
	public static String encrypt(String username, String password) {
		if (StrKit.isBlank(username)) {
			throw new RuntimeException("the username is blank");
		}

		if (StrKit.isBlank(password)) {
			throw new RuntimeException("the password is blank");
		}

//		if (username.length() < 5) {
//			throw new RuntimeException("the username is too short");
//		}
//
//		if (password.length() < 64) {
//			throw new RuntimeException("the password is not sha256");
//		}

		String salt = HashKit.md5(username).substring(2, 10);
		return HashKit.sha256(salt + password);
	}

}