⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5tools.java

📁 陕西电信sp客户端
💻 JAVA
字号:
// ----------------------------------------------------------------------------
// $Source $
// ----------------------------------------------------------------------------
// Copyright (c) 2002 by Onewave Inc.
// ----------------------------------------------------------------------------
// $Id: MD5Tools.java,v 1.1.1.1 2006/08/01 05:49:34 zhengx Exp $
// ----------------------------------------------------------------------------
// $Log: MD5Tools.java,v $
// Revision 1.1.1.1  2006/08/01 05:49:34  zhengx
// no message
//
// Revision 1.1  2006/06/02 03:33:17  wuyan
// *** empty log message ***
//
// Revision 1.1  2005/12/08 10:37:42  like
// no message
//
// Revision 1.1  2003/07/28 06:30:32  zengc
// no message
//
// ----------------------------------------------------------------------------

package com.onewaveinc.portalman.webpro.security;

/**
 * <p>Title: PortalMAN SDK API Documentation</p>
 * <p>Description: OneWave Technologies., Inc. PortalMAN Value-add Management Platform 3rd Software Development Kit</p>
 * <p>Copyright: Copyright (c) 2002 </p>
 * <p>Company: OneWave Technologies., Inc.</p>
 * @author 3rd AAA & ICP Integration Developement Team
 * @version 1.5
 */



import java.util.*;
import java.security.*;
import java.text.*;

public class MD5Tools{


	private static MessageDigest md;

	static{
	try{
		if(md==null){
		md = MessageDigest.getInstance("MD5");
		}
	}catch(Exception e){
		e.printStackTrace();
	}

	}

	public static String bytes2string(byte[] bytes){
	return new String(bytes);
	}
	public static byte[] string2bytes(String str){
	return str.getBytes();
	}


/*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
 因为java中的byte的toString无法实现这一点,我们又没有C语言中的
sprintf(outbuf,"%02X",ib)
*/
	public static String byte2HEX(byte b) {
	return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF));
	}

	public static byte stringHEX2bytes(String str) {
	return (byte) ("0123456789ABCDEF".indexOf(str.substring(0,1))*16 + "0123456789ABCDEF".indexOf(str.substring(1)));
	}
	public static byte[] addbytes(byte[] b1,byte[] b2){
	byte[] b = new byte[b1.length + b2.length];
	System.arraycopy(b1, 0, b, 0, b1.length);
	System.arraycopy(b2, 0, b, b1.length, b2.length);
	return b;
	}
	public static byte[] addbytes(byte[] b1,String str1){
	return addbytes(b1,string2bytes(str1));
	}
	public static byte[] addbytes(String str1,byte[] b1){
	return addbytes(string2bytes(str1),b1);
	}
	public static byte[] addbytes(String str1,String str2){
	return addbytes(string2bytes(str1),string2bytes(str2));
	}


	public static String md5bytes2string(byte[] bytes){
	String result = "";
	for(int i=0; i<bytes.length; i++){
		result += byte2HEX(bytes[i]);
	}
	return result;
	}
	public static byte[] md5string2bytes(String str){
	byte[] b = new byte[str.length()/2];
	for(int i=0; i<b.length; i++){
		String s = str.substring(i*2,i*2+2);
		b[i] = stringHEX2bytes(s);
	}
	return b;
	}

	public static byte[] getAuthSeed(){
	byte[] b = new byte[16];
	for(int i=0; i< b.length; i++){
		b[i] = (byte)(Math.random()*1024);
	}
	return b;
	}
	public static byte[] getAuthSeed(int length){
	byte[] b = new byte[length];
	for(int i=0; i< b.length; i++){
		b[i] = (byte)(Math.random()*1024);
	}
	return b;
	}

	public static byte[] getAuthCodebySeed(byte[] seed){
	return md.digest(seed);
	}

	public static String date2string(Date date){
	if(date == null){
		return null;
	}
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	return dateFormat.format(date);
	}
	private static String get2byteString(int in){
	String a = "00" + in;
	return a.substring(a.length()-2,a.length());
	}

	public static String float2string(float f){
	String s = String.valueOf(f) + "00";
	int index = s.indexOf(".");
	return s.substring(0,index+3);
	}





}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -