java实现md5和aes加密解密
一、MD5加密
else hs = hs + stmp;}
return hs.toUpperCase();
}
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0) throw new IllegalArgumentException("长度不是偶数");
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
/**
* 解密
*
* @param data
* @return
* @throws Exception
*/
public final static String decrypt(String data) {
try {
return new String(decrypt(hex2byte(data.getBytes()), CRYPT_KEY));
} catch (Exception e) {
}
return null;
}
/**
* 加密
*
* @param data
* @return
* @throws Exception
*/
public final static String encrypt(String data) {
try {
return byte2hex(encrypt(data.getBytes(), CRYPT_KEY));
} catch (Exception e) {
}
return null;
}
public static void main(String[] args) {
String ID = "11112222";
String idEncrypt = encrypt(ID);
System.out.println(idEncrypt);
String idDecrypt = decrypt(idEncrypt);
System.out.println(idDecrypt);
}
}
?