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");