MD5加密及随机数生成

今天贴两个简单的方法,需要的时候不用自己再写,

 

	public static String md5(String plaintext){
		MessageDigest m;
		try {
			m = MessageDigest.getInstance("MD5");
			m.reset(); 
			m.update(plaintext.getBytes()); 
			byte[] digest = m.digest(); 
			BigInteger bigInt = new BigInteger(1,digest); 
			String hashtext = bigInt.toString(16); 
			// Now we need to zero pad it if you actually want the full 32 chars. 
			while(hashtext.length() < 32 ){ 
			  hashtext = "0"+hashtext; 
			} 
			return hashtext;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return System.currentTimeMillis() + "";
		} 
	}


	public static String randomCreator(int num){
		Random random = new Random();
		int i=random.nextInt();
		i=Math.abs(i);
		
		String tem=String.valueOf(i);
		while(tem.length()
 

 

 

你可能感兴趣的:(Java,综合)