📄 phsutil.java
字号:
package sms.PHS;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.PrintStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
class PHSUtil
{
private static MessageDigest digest = null;
private static final char zeroArray[] = "0000000000000000".toCharArray();
PHSUtil()
{
}
/**
* return byte abyte1
* @param abyte0
* @return
*/
public static byte[] copyBytes(byte abyte0[])
{
if(abyte0 == null || abyte0.length <= 0)
return null;
byte abyte1[] = new byte[abyte0.length];
for(int i = 0; i < abyte0.length; i++)
abyte1[i] = abyte0[i];
return abyte1;
}
/**
* tranform to the hex
* @param bytes
* @return
*/
public static final String encodeHex(byte bytes[])
{
StringBuffer buf = new StringBuffer(bytes.length * 2);
for(int i = 0; i < bytes.length; i++)
{
if((bytes[i] & 0xff) < 16)
buf.append("0");
buf.append(Long.toString(bytes[i] & 0xff, 16));
}
return buf.toString();
}
public static byte[] getBytes(String s, int len)
{
if(s == null)
return new byte[0];
if(s.length() > len)
len = s.length();
byte abyte1[] = new byte[len];
System.arraycopy(s.getBytes(), 0, abyte1, 0, s.length());
return abyte1;
}
/**
* get the TimeStamp
* @return
*/
public static int getTimestamp()
{
String sNow = getTimestampString();
return Integer.parseInt(sNow);
}
public static String getTimestampString()
{
Date now = new Date();
SimpleDateFormat dateformat = new SimpleDateFormat("MMddHHmmss");
String sNow = dateformat.format(now);
return sNow;
}
public static final synchronized byte[] hash(String data)
{
/**
if(digest != null)
break MISSING_BLOCK_LABEL_36;
digest = MessageDigest.getInstance("MD5");
break MISSING_BLOCK_LABEL_35;
NoSuchAlgorithmException nsae;
nsae;
System.err.println("Failed to load the MD5 MessageDigest. We will be unable to function normally.");
nsae.printStackTrace();
digest.update(data.getBytes());
return digest.digest();
*/
// if(digest != null){
//break MISSING_BLOCK_LABEL_36;
try {
digest = MessageDigest.getInstance("MD5");
digest.update(data.getBytes()); //添加要进行计算摘要的信息
}
catch (NoSuchAlgorithmException nsae) {
nsae.printStackTrace();
System.err.println(
"Failed to load the MD5 MessageDigest. We will be unable to function normally.");
}
//}
return digest.digest(); //计算出摘要
}
public static String toHexStr(String str0)
{
byte abyte0[] = str0.getBytes();
String s = "";
for(int i = 0; i < abyte0.length; i++)
s = s + toHexStr(abyte0[i]);
return new String(s);
}
public static String toHexStr(byte abyte0[])
{
String s = "";
for(int i = 0; i < abyte0.length; i++)
s = s + toHexStr(abyte0[i]);
return new String(s);
}
public static String toHexStr(int i)
{
String s = "";
for(int j = 0; j < 8; j++)
{
s = s + Character.forDigit(i & 0xf, 16);
i >>= 4;
}
String s1 = "";
for(int k = 8; k > 0; k--)
s1 = s1 + s.charAt(k - 1);
return new String(s1);
}
public static String toHexStr(byte byte0)
{
String s = "";
s = s + Character.forDigit(byte0 >> 4 & 0xf, 16);
s = s + Character.forDigit(byte0 & 0xf, 16);
return new String(s);
}
public static final String zeroPadString(String string, int length)
{
if(string == null || string.length() > length)
{
return string;
} else
{
StringBuffer buf = new StringBuffer(length);
buf.append(zeroArray, 0, length - string.length()).append(string);
return buf.toString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -