📄 encode_md5.java
字号:
package com.qq.content;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.security.*;
public class Encode_md5{
public static String curTime;
public static String getTime()
{
Date timeer = new Date(); // 取当前的时间
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); // 设置显示的格式
String msg = df.format(timeer); // msg中存放格式化后的时间字串
System.out.println(msg);
return msg;
}
public static String encode(String mobile)
{
String tm = getTime();
curTime = tm;
return getDigest(mobile+tm, "abcdefghijklmkopqrstuvwxyz");
}
public static String encode(String mobile, String tm)
{
return getDigest(mobile+tm, "abcdefghijklmkopqrstuvwxyz");
}
public static String getDigest(String str, String key) {
String outline=null;
byte[] salt = new byte[50];
int i;
if(str==null)
return null;
for (i = 0; i < salt.length; ++i) {
salt[i] = 3;
}
byte[] srcBytes = str.getBytes();
byte[] keyBytes = key.getBytes();
int bt=(srcBytes.length<keyBytes.length?srcBytes.length:keyBytes.length);
for (i = 0; i < bt; ++i) {//加密算法,产生密钥
salt[i] = (byte)(srcBytes[i%bt]^keyBytes[i%bt]);
}
try {
MessageDigest digester = java.security.MessageDigest.getInstance("MD5");
digester.update(salt);
byte[] digesta = digester.digest();
outline = byte2hex(digesta);
System.out.println("OUT:" + outline);
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return outline;
}
public static String byte2hex(byte[] b) //二行制转字符串
{
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs;
}
public static void main(String[] args) {
String mobileNum = "13888889999";
String time = "20060501000000";
String out=Encode_md5.getDigest(mobileNum + time, "abcdefghijklmkopqrstuvwxyz");//加密串
System.out.println("out put is "+out);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -