import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.PRintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Created by IntelliJ IDEA.
* User: zhengzhg
* Mail: snake_country@sina.com
* Date: 2004-10-13
* Time: 15:30:28
* To change this template use File Settings File Templates.
* 常用工具包。包括生成各種密碼隨機串,加密解密,編碼解碼,執行url等
*/
public class CryptTool {
/**
* 生成密碼.
* @param count 密碼位數
* @param letters 是否包含字符
* @param numbers 是否包含數字
* @return String passWord
*/
public static String getPassword(int count, boolean letters, boolean numbers) {
return org.apache.commons.lang.RandomStringUtils.random(count, letters, numbers);
}
/**
* 生成字符數字混合的密碼.
* @param count 密碼位數
* @return String password
*/
private static String getPassword(int count) {
return getPassword(count, true, true);
}
/**
* 生成純數字密碼.
* @param count 密碼位數
* @return String password
*/
public static String getPasswordOfNumber(int count) {
return getPassword(count, false, true);
}
/**
* 生成純字符密碼.
* @param count 密碼位數
* @return String password
*/
public static String getPasswordOfCharacter(int count) {
return getPassword(count, true, false);
}
/**
* 生成3DES密鑰.
* @param key_byte seed key
* @throws Exception
* @return javax.crypto.SecretKey Generated DES key
*/
public static javax.crypto.SecretKey genDESKey(byte[] key_byte) throws Exception {
SecretKey k = new SecretKeySpec(key_byte, "DESede");
新聞熱點
疑難解答