-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStringUtil.java
More file actions
53 lines (46 loc) · 1.6 KB
/
StringUtil.java
File metadata and controls
53 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.bookshop.util;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
public class StringUtil {
public static boolean isEmpty(String str) {
if (str == null || str.length() == 0) {
return true;
}
return false;
}
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
//随机生成6位数主键
public static Long seqGenerate(){
//获取当前时间毫秒数
long mTime = System.currentTimeMillis();
//随机生成6位随机数
long radomNum = (int)((Math.random()*9+1)*100000);
//System.out.println(mTime + "" + radomNum);
long seq = mTime*1000000+radomNum;
return seq;
}
//MD5加密
public static String EncoderByMd5(String password) {
try {
//返回实现指定摘要算法的 MessageDigest对象。
MessageDigest md=MessageDigest.getInstance("MD5");
//得到一个操作系统默认的字节编码格式的字节数组
md.update(password.getBytes());
// digest()最后确定返回md5 hash值,返回值为8为字符串。
//因为md5 hash值是16位的hex值,实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;
//得到字符串形式的hash值
return new BigInteger(1, md.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
/*public static void main(String[] args) {
System.out.println(StringUtil.EncoderByMd5("123456"));
}*/
}