- 浏览: 572185 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (267)
- 随笔 (4)
- Spring (13)
- Java (61)
- HTTP (3)
- Windows (1)
- CI(Continuous Integration) (3)
- Dozer (1)
- Apache (11)
- DB (7)
- Architecture (41)
- Design Patterns (11)
- Test (5)
- Agile (1)
- ORM (3)
- PMP (2)
- ESB (2)
- Maven (5)
- IDE (1)
- Camel (1)
- Webservice (3)
- MySQL (6)
- CentOS (14)
- Linux (19)
- BI (3)
- RPC (2)
- Cluster (9)
- NoSQL (7)
- Oracle (25)
- Loadbalance (7)
- Web (5)
- tomcat (1)
- freemarker (1)
- 制造 (0)
最新评论
-
panamera:
如果设置了连接需要密码,Dynamic Broker-Clus ...
ActiveMQ 集群配置 -
panamera:
请问你的最后一种模式Broker-C节点是不是应该也要修改持久 ...
ActiveMQ 集群配置 -
maosheng:
longshao_feng 写道楼主使用 文件共享 模式的ma ...
ActiveMQ 集群配置 -
longshao_feng:
楼主使用 文件共享 模式的master-slave,produ ...
ActiveMQ 集群配置 -
tanglanwen:
感触很深,必定谨记!
少走弯路的十条忠告
import java.security.MessageDigest;
public class MD5Util {
public final static String MD5(String s) {
char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
try {
byte[] btInput = s.getBytes();
MessageDigest mdInst = MessageDigest.getInstance("MD5");
mdInst.update(btInput);
byte[] md = mdInst.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
System.out.println(MD5Util.MD5("张三"));
}
}
import java.io.*;
import java.security.*;
public class MD5
{
public static String md5Str(String str)
{
if (str == null)return "";
return md5Str(str, 0);
}
/**
* 计算消息摘要。
* @param data 计算摘要的数据。
* @param offset 数据偏移地址。
* @param length 数据长度。
* @return 摘要结果。(16字节)
*/
public static String md5Str(String str, int offset)
{
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] b = str.getBytes("UTF8");
md5.update(b, offset, b.length);
return byteArrayToHexString(md5.digest());
}
catch (NoSuchAlgorithmException ex)
{
ex.printStackTrace();
return null;
}
catch (UnsupportedEncodingException ex)
{
ex.printStackTrace();
return null;
}
}
/**
*
* @param b byte[]
* @return String
*/
public static String byteArrayToHexString(byte[] b)
{
String result = "";
for (int i = 0; i < b.length; i++)
{
result += byteToHexString(b[i]);
}
return result;
}
private static String[] hexDigits =
{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b",
"c", "d", "e", "f"};
/**
* 将字节转换为对应的16进制明文
* @param b byte
* @return String
*/
public static String byteToHexString(byte b)
{
int n = b;
if (n < 0)
{
n = 256 + n;
}
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
public static void main(String[] args)
{
System.out.println(byteToHexString((byte)-99));
String str =
"eeeeeeeeeeeeee213123122222222222222222222222213123213213213aaaa";
String ened = MD5.md5Str(str);
System.out.println(ened.length());
System.out.println(ened);
}
}
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class StringUtil {
public StringUtil() {
}
public static void main(String[] args) {
// String keyStr = "8E62AC0A5FAFB7939D077B668C6718ED36306A8E21DABC4D";
// String pinKey = keyStr.substring(0,keyStr.length()/2);
// String macKey = keyStr.substring(keyStr.length()/2 , keyStr.length());
// String key = "1111111111111111";
// String macCheck = "21DABC4D"; //macKey.substring(macKey.length()-8 , macKey.length());
// macKey = "8C6718ED36306A8E" ;//"8C6718ED36306A8E" ;//macKey.substring(0 , 16);
// String desRes = desCbc(key , macKey , "00" , 1);
// desRes = desCbc(desRes , "0000000000000000" , "00" , 0);
// System.out.println(desRes);
// System.out.println(macCheck);
String tempkey = "1111111111111111";
try {
String encodeKey = Base64.encode(tempkey);
System.out.println("encodeKey:"+encodeKey);
byte[] decodeByte = Base64.decode(encodeKey);
System.out.println(decodeByte);
String decodeKey = new String(decodeByte,"utf-8");
System.out.println("decodeKey:"+decodeKey);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String key = "9DF4AE671CA79846";
//43423341
String data= "12003020048030C08013000000000000012320000001022000279999000000395344D151272520600026999999000000395344D53827273831303430303830303030313031303430303030303034313536001350000001000500002543555030313639393537383538353435202020202020202020";
System.out.println(key);
System.out.println("43423341");
// System.out.println(macUtil.ecbBytesTest(StringUtil.hexToBytes(data),key));
System.out.println(create8583Mac(key, data));
}
public static String create8583Mac(String key ,String message){
byte[] b = StringUtil.hexToBytes(message);
byte[] b8 = new byte[b.length + (8-b.length%8)];
System.arraycopy(b, 0, b8, 0, b.length);
byte[] temp = new byte[8];
for(int i =0 ; i<b8.length ; i++){
if(i<8){
temp[i] = b8[i];
}else{
temp[i%8] = (byte) (temp[i%8]^ b8[i]);
}
}
String hex = StringUtil.byteToHex(temp);
String desRes1 = desEcb(key , StringUtil.byteToHex(hex.getBytes(),0,8) , "00" , 0);
byte[] desResByte = StringUtil.hexToBytes(desRes1);
for(int i =0 ; i<desResByte.length ; i++){
desResByte[i] = (byte) (desResByte[i] ^ hex.getBytes()[i+8]);
}
String desRes2 = desEcb(key , StringUtil.byteToHex(desResByte) , "00" , 0);
return desRes2.substring(0,8);
}
/**
* 0加密 1解密
* @param key
* @param data
* @param padding "80" "20" "00"
* @param mode 0加密 1解密
* @return
*/
public static String desEcb(String key , String srcData) {
try{
SecretKey keySpec = new SecretKeySpec(StringUtil.hexToBytes(key), "DES");// key
Cipher enc = Cipher.getInstance("DES/ECB/NoPadding");
enc.init(Cipher.ENCRYPT_MODE , keySpec);
byte[] temp = enc.doFinal(StringUtil.hexToBytes(srcData));
return StringUtil.byteToHex(temp,0,8);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
/**
* 0加密 1解密
* @param key
* @param data
* @param padding "80" "20" "00"
* @param mode 0加密 1解密
* @return
*/
public static String desEcb(String key , String srcData , String padding , int mode) {
try{
if(key.length()%2!=0 || key.length()/2 !=8){
return null;
}
if((srcData.length()/2)%8!=0){
srcData =srcData+padding;
}
while((srcData.length()/2)%8!=0){
srcData = srcData+"00";
}
SecretKey keySpec = new SecretKeySpec(StringUtil.hexToBytes(key), "DES");// key
Cipher enc = Cipher.getInstance("DES/ECB/NoPadding");
int cipherType = (mode == 0 ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE);
enc.init(cipherType , keySpec);
byte[] temp = enc.doFinal(StringUtil.hexToBytes(srcData));
return StringUtil.byteToHex(temp,0,8);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
/**
* 将16进制字符串转为2进制的bitMap
* @param bitMap
* @return
*/
public static String dispackageBitMap(String bitMap){
StringBuffer buffer = new StringBuffer();
for(int i =0 ; i<bitMap.length() ; i++){
int x = Integer.parseInt(bitMap.charAt(i)+"" , 16);
buffer.append(StringUtil.padding(Integer.toBinaryString(x) , 4 , 1 , 1));
}
return buffer.toString();
}
/**
* 补位
* @param src 源
* @param length 补充到的长度
* @param paddingType 1:补0 2:补空格
* @param leftOrRight 1:左补 2:右补
* @return
*/
public static String padding(String src , int length , int paddingType , int leftOrRight){
String padddingStr = null;
StringBuffer buffer = new StringBuffer(src);
if(paddingType == 1){
padddingStr = "0";
}else{
padddingStr = " ";
}
while(buffer.length() < length){
if(leftOrRight == 1){
buffer.insert(0, padddingStr);
}else{
buffer.append(padddingStr);
}
}
return buffer.toString();
}
/**
* 个人标识码(PIN)加密
* @param pin 6-12个数 不在此范围内返回空
* @param dataTwo 2磁道数据
* @return 个人标识码
* @throws UnsupportedEncodingException
*/
public static String getSecPin(String pin , String dataTwo, String key) throws UnsupportedEncodingException{
if(pin.length() >12 || pin.length()<6){
return null;
}
String pinHex = pin;
if(pin.length() >=10){
pinHex = pin.length()+pinHex;
}else{
pinHex = "0"+pin.length()+pinHex;
}
while(pinHex.length()<16){
pinHex +="F";
}
byte[] pinByte = StringUtil.hexToBytes(pinHex);
int dindex = dataTwo.toLowerCase().indexOf("d");
if(dindex < 0){
dindex = dataTwo.length();
}else{
dindex = dataTwo.toLowerCase().indexOf("d");
}
dataTwo = dataTwo.substring(dindex-13,dindex-1);
dataTwo = "0000"+dataTwo;
byte[] panByte = StringUtil.hexToBytes(dataTwo);
byte[] result = new byte[8];
for(int i =0 ; i<result.length ; i++){
result[i] = (byte) (pinByte[i]^panByte[i]);
}
String temp = key.substring(0,16);
String mainkey = ReadConfig.getValue("mainKey");
String decodekey = new String(Base64.decode(mainkey),"utf-8");
String pinkey = StringUtil.desEcb(decodekey, temp, "00", 1);
String checkKey = StringUtil.desEcb(pinkey, "0000000000000000","00",0);
System.out.println("checkKey : "+checkKey+" 9-12字节"+key.substring(16,24));
String passwordo = StringUtil.desEcb(pinkey, StringUtil.byteToHex(result), "00", 0);
return passwordo;
}
public static String byteBufferToString(java.nio.ByteBuffer buffer) {
Charset charset = null;
CharsetDecoder decoder = null;
CharBuffer charBuffer = null;
try {
charset = Charset.forName("UTF-8");
decoder = charset.newDecoder();
charBuffer = decoder.decode(buffer);
return charBuffer.toString();
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
}
public static String byteBufferToString(java.nio.ByteBuffer[] buffer) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < buffer.length; i++) {
sb.append(byteBufferToString(buffer[i]));
}
return sb.toString();
}
/**
* 返回512长度之内的HEX字符串除以2之后的长度,用HEX字符串表示
* 例如传递的字符串长度为280,其16进制长度为140(0x8C),用字符串8c表示
*
* @param strValue
* @return
*/
public static String getStringHexLenWithinByte(String strValue) {
int len = strValue.length() / 2;
String result = Integer.toHexString(len);
if (result.length() == 1) {
result = "0" + result;
}
return result;
}
public static String trimStringBlank(String strValue) {
String result = strValue.trim(); // 去掉左右的空格
String space = " ";
String tabCh = Character.toString((char) 9);
// 去除中间的空格
result = result.replaceAll(space, "");
result = result.replaceAll(tabCh, "");
return result;
}
public static int getHexDataLen(String data) {
String strTemp = data.replaceAll(" ", "");
return strTemp.length();
}
public static String formatHexDataWithSpace(String data) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < data.length(); i++) {
if (i > 0 && (i % 2 == 0)) {
buffer.append(" ");
}
buffer.append(data.charAt(i));
}
return buffer.toString();
}
public static String asciiToHex(String asciiString) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
byte[] buff = asciiString.getBytes();
for (int i = 0; i < buff.length; i++) {
iValue = buff[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
/**
* 以指定的字符编码解析字符串的长度
*
* @param txt
* 要解析的字符串
* @param charset
* 编码
* @return 字符串的长度
*/
public static int getStrLength(String txt, String charset) {
try {
return txt.getBytes(charset).length;
} catch (UnsupportedEncodingException ex) {
return txt.length();
}
}
public static String byteToHex(byte[] buffer, int offset, int len) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
for (int i = offset; i < offset + len; i++) {
iValue = buffer[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String byteToHex(byte[] buffer) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
for (int i = 0; i < buffer.length; i++) {
iValue = buffer[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String asciiToHex(byte[] hexBuffer, int iOffset, int iLen) {
StringBuffer hexString = new StringBuffer();
String hex;
int byteValue;
for (int i = iOffset; i < iOffset + iLen; i++) {
byteValue = hexBuffer[i];
if (byteValue < 0) {
byteValue += 256;
}
hex = Integer.toString(byteValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String intToHex(int value) {
String hex;
hex = Integer.toString(value, 16);
if (hex.length() % 2 != 0) {
hex = "0" + hex;
}
return hex.toUpperCase();
}
public static byte[] intToBytes(int value , int byteSize) {
String hex = StringUtil.Int2HexStr(value, byteSize*2);
return StringUtil.hexToBytes(hex);
}
/**
* @param hex
* 将16进制的ascii 转成中文
* @return
*/
public static String hexToAscii(String hex) {
byte[] buffer = new byte[hex.length() / 2];
String strByte;
for (int i = 0; i < buffer.length; i++) {
strByte = hex.substring(i * 2, i * 2 + 2);
buffer[i] = (byte) Integer.parseInt(strByte, 16);
}
return new String(buffer);
}
/**
* @param hex
* 每两个字节进行处理
* @return
*/
public static byte[] hexToBytes(String hex) {
byte[] buffer = new byte[hex.length() / 2];
String strByte;
for (int i = 0; i < buffer.length; i++) {
strByte = hex.substring(i * 2, i * 2 + 2);
buffer[i] = (byte) Integer.parseInt(strByte, 16);
}
return buffer;
}
/**
* @param hex
* 每两个字节进行处理
* @return
*/
public static byte[] hexToBytesVip(String hex) {
byte[] buffer = hex.getBytes();
byte[] buff = new byte[buffer.length-14];
for(int i=14;i<buffer.length;i++){
buff[i-14] = buffer[i];
}
return buff;
}
public static boolean hasChineseChar(String strValue) {
boolean bResult = false;
byte[] temp = strValue.getBytes();
for (int i = 0; i < strValue.length(); i++) {
if (temp[i] < 0) {
bResult = true;
break;
}
}
return bResult;
}
public static boolean isNull(String value) {
boolean bIsNull = false;
if (value == null) {
bIsNull = true;
return bIsNull;
}
if (value.trim().length() == 0) {
bIsNull = true;
}
return bIsNull;
}
public static String formatWithSpace(String value) {
String formatedValue = value;
String retValue;
// 去掉所有的空格
formatedValue = trimStringBlank(formatedValue);
if (formatedValue.length() % 2 != 0) {
formatedValue = formatedValue + "0";
}
retValue = "";
for (int i = 0; i < formatedValue.length(); i += 2) {
retValue += formatedValue.substring(i, i + 2) + " ";
}
return retValue;
}
public static String formatDateToString(Date date) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
return sdf.format(date);
}
public static String formatDateToString(Date date, String format) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
/**
* 将一个byte数组转换为字符串
*
* @param arr
* 要转换的byte数组
* @return 转换好的字符串,如果数组的length=0,则返回""。
*/
public static String bytetoString(byte[] arr) {
String str = "";
String tempStr = "";
for (int i = 1; i < arr.length; i++) {
tempStr = (Integer.toHexString(arr[i] & 0xff));
if (tempStr.length() == 1) {
str = str + "0" + tempStr;
} else {
str = str + tempStr;
}
}
return str;
}
public static boolean isChineaseLetter(String name) {
Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5]*$");
Matcher isNum = pattern.matcher(name);
if (!isNum.matches()) {
return false;
}
return true;
}
/**
* 获取字符串的长度,如果有中文,则每个中文字符计为2位
*
* @param value
* 指定的字符串
* @return 字符串的长度
*/
public static int length(String value) {
int valueLength = 0;
String chinese = "[\u0391-\uFFE5]";
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
for (int i = 0; i < value.length(); i++) {
/* 获取一个字符 */
String temp = value.substring(i, i + 1);
/* 判断是否为中文字符 */
if (temp.matches(chinese)) {
/* 中文字符长度为2 */
valueLength += 2;
} else {
/* 其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;
}
public static String formatDateToEngString(Date date) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
public static String splitAndFilterString(String input, int length) {
if (input == null || input.trim().equals("")) {
return "";
}
// 去掉所有html元素,
String str = input.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll(
"<[^>]*>", "");
str = str.replaceAll("[(/>)<]", "");
int len = str.length();
if (len <= length) {
return str;
} else {
str = str.substring(0, length);
str += "......";
}
return str;
}
/**
* 将字符串格式化为指定的长度整数倍,不足填充对齐
*
* @param data
* @param len
* @param fill
* @return
*/
public static String formatStringByLen(String data, int len, String fill) {
String strData = trimStringBlank(data);
int iFilledLen = strData.length() % len;
if (iFilledLen > 0) {
for (int i = 0; i < 8 - iFilledLen; i++) {
strData += fill;
}
}
return strData;
}
/**
* BCD字符串转换成byte数组
*
* @param data
* @return
*/
public static byte[] bcdToBytes(String data) {
String strData = trimStringBlank(data).toUpperCase();
String str;
int value;
int j = 0;
byte[] bData = new byte[strData.length() / 2];
for (int i = 0; i < strData.length(); i++) {
value = Character.digit(strData.charAt(i), 16);
bData[j] = (byte) ((value << 4) & 0xF0);
value = Character.digit(strData.charAt(i + 1), 16);
bData[j] |= (byte) (value & 0x0F);
i++;
j++;
}
return bData;
}
public static String getSeperatedPathFromPackage(String rootPackage) {
String path = rootPackage.replaceAll("\\.", "\\" + File.separator);
if (!path.endsWith(File.separator)) {
path += File.separator;
}
return path;
}
/**
* @param data
* byte 0x 01
* @return 01
*/
public static String byteToHexStr(byte data) {
String result = Integer.toString((data & 0xff) + 0x100, 16)
.substring(1);
return result;
}
/**
* 将整数转为16进行数后并以指定长度返回(当实际长度大于指定长度时只返回从末位开始指定长度的值)
*
* @param val
* int 待转换整数
* @param len
* int 指定长度
* @return String
*/
public static String Int2HexStr(int val, int len) {
String result = Integer.toHexString(val).toUpperCase();
int r_len = result.length();
if (r_len > len) {
return result.substring(r_len - len, r_len);
}
if (r_len == len) {
return result;
}
StringBuffer strBuff = new StringBuffer(result);
for (int i = 0; i < len - r_len; i++) {
strBuff.insert(0, '0');
}
return strBuff.toString();
}
public static String ucs2Decode(byte[] btsrc) {
if (btsrc == null || btsrc.length == 0) {
return "";
}
String retstr = "";
int nLen = (int) btsrc.length;
byte[] bt;
try {
if (btsrc[0] == (byte) 0x80) {
bt = new byte[nLen - 1];
System.arraycopy(btsrc, 1, bt, 0, nLen - 1);
retstr = (new String(bt, "UTF-16BE"));
} else {
bt = new byte[nLen];
System.arraycopy(btsrc, 0, bt, 0, nLen);
retstr = (new String(bt, "ISO-8859-1"));
}
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
return retstr;
}
public static void BytesCopy(byte[] dest, byte[] source, int offset1,
int offset2, int len) {
for (int i = 0; i < len; i++) {
dest[offset1 + i] = source[offset2 + i];
}
}
}
public class MD5Util {
public final static String MD5(String s) {
char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
try {
byte[] btInput = s.getBytes();
MessageDigest mdInst = MessageDigest.getInstance("MD5");
mdInst.update(btInput);
byte[] md = mdInst.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
System.out.println(MD5Util.MD5("张三"));
}
}
import java.io.*;
import java.security.*;
public class MD5
{
public static String md5Str(String str)
{
if (str == null)return "";
return md5Str(str, 0);
}
/**
* 计算消息摘要。
* @param data 计算摘要的数据。
* @param offset 数据偏移地址。
* @param length 数据长度。
* @return 摘要结果。(16字节)
*/
public static String md5Str(String str, int offset)
{
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] b = str.getBytes("UTF8");
md5.update(b, offset, b.length);
return byteArrayToHexString(md5.digest());
}
catch (NoSuchAlgorithmException ex)
{
ex.printStackTrace();
return null;
}
catch (UnsupportedEncodingException ex)
{
ex.printStackTrace();
return null;
}
}
/**
*
* @param b byte[]
* @return String
*/
public static String byteArrayToHexString(byte[] b)
{
String result = "";
for (int i = 0; i < b.length; i++)
{
result += byteToHexString(b[i]);
}
return result;
}
private static String[] hexDigits =
{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b",
"c", "d", "e", "f"};
/**
* 将字节转换为对应的16进制明文
* @param b byte
* @return String
*/
public static String byteToHexString(byte b)
{
int n = b;
if (n < 0)
{
n = 256 + n;
}
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
public static void main(String[] args)
{
System.out.println(byteToHexString((byte)-99));
String str =
"eeeeeeeeeeeeee213123122222222222222222222222213123213213213aaaa";
String ened = MD5.md5Str(str);
System.out.println(ened.length());
System.out.println(ened);
}
}
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class StringUtil {
public StringUtil() {
}
public static void main(String[] args) {
// String keyStr = "8E62AC0A5FAFB7939D077B668C6718ED36306A8E21DABC4D";
// String pinKey = keyStr.substring(0,keyStr.length()/2);
// String macKey = keyStr.substring(keyStr.length()/2 , keyStr.length());
// String key = "1111111111111111";
// String macCheck = "21DABC4D"; //macKey.substring(macKey.length()-8 , macKey.length());
// macKey = "8C6718ED36306A8E" ;//"8C6718ED36306A8E" ;//macKey.substring(0 , 16);
// String desRes = desCbc(key , macKey , "00" , 1);
// desRes = desCbc(desRes , "0000000000000000" , "00" , 0);
// System.out.println(desRes);
// System.out.println(macCheck);
String tempkey = "1111111111111111";
try {
String encodeKey = Base64.encode(tempkey);
System.out.println("encodeKey:"+encodeKey);
byte[] decodeByte = Base64.decode(encodeKey);
System.out.println(decodeByte);
String decodeKey = new String(decodeByte,"utf-8");
System.out.println("decodeKey:"+decodeKey);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String key = "9DF4AE671CA79846";
//43423341
String data= "12003020048030C08013000000000000012320000001022000279999000000395344D151272520600026999999000000395344D53827273831303430303830303030313031303430303030303034313536001350000001000500002543555030313639393537383538353435202020202020202020";
System.out.println(key);
System.out.println("43423341");
// System.out.println(macUtil.ecbBytesTest(StringUtil.hexToBytes(data),key));
System.out.println(create8583Mac(key, data));
}
public static String create8583Mac(String key ,String message){
byte[] b = StringUtil.hexToBytes(message);
byte[] b8 = new byte[b.length + (8-b.length%8)];
System.arraycopy(b, 0, b8, 0, b.length);
byte[] temp = new byte[8];
for(int i =0 ; i<b8.length ; i++){
if(i<8){
temp[i] = b8[i];
}else{
temp[i%8] = (byte) (temp[i%8]^ b8[i]);
}
}
String hex = StringUtil.byteToHex(temp);
String desRes1 = desEcb(key , StringUtil.byteToHex(hex.getBytes(),0,8) , "00" , 0);
byte[] desResByte = StringUtil.hexToBytes(desRes1);
for(int i =0 ; i<desResByte.length ; i++){
desResByte[i] = (byte) (desResByte[i] ^ hex.getBytes()[i+8]);
}
String desRes2 = desEcb(key , StringUtil.byteToHex(desResByte) , "00" , 0);
return desRes2.substring(0,8);
}
/**
* 0加密 1解密
* @param key
* @param data
* @param padding "80" "20" "00"
* @param mode 0加密 1解密
* @return
*/
public static String desEcb(String key , String srcData) {
try{
SecretKey keySpec = new SecretKeySpec(StringUtil.hexToBytes(key), "DES");// key
Cipher enc = Cipher.getInstance("DES/ECB/NoPadding");
enc.init(Cipher.ENCRYPT_MODE , keySpec);
byte[] temp = enc.doFinal(StringUtil.hexToBytes(srcData));
return StringUtil.byteToHex(temp,0,8);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
/**
* 0加密 1解密
* @param key
* @param data
* @param padding "80" "20" "00"
* @param mode 0加密 1解密
* @return
*/
public static String desEcb(String key , String srcData , String padding , int mode) {
try{
if(key.length()%2!=0 || key.length()/2 !=8){
return null;
}
if((srcData.length()/2)%8!=0){
srcData =srcData+padding;
}
while((srcData.length()/2)%8!=0){
srcData = srcData+"00";
}
SecretKey keySpec = new SecretKeySpec(StringUtil.hexToBytes(key), "DES");// key
Cipher enc = Cipher.getInstance("DES/ECB/NoPadding");
int cipherType = (mode == 0 ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE);
enc.init(cipherType , keySpec);
byte[] temp = enc.doFinal(StringUtil.hexToBytes(srcData));
return StringUtil.byteToHex(temp,0,8);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
/**
* 将16进制字符串转为2进制的bitMap
* @param bitMap
* @return
*/
public static String dispackageBitMap(String bitMap){
StringBuffer buffer = new StringBuffer();
for(int i =0 ; i<bitMap.length() ; i++){
int x = Integer.parseInt(bitMap.charAt(i)+"" , 16);
buffer.append(StringUtil.padding(Integer.toBinaryString(x) , 4 , 1 , 1));
}
return buffer.toString();
}
/**
* 补位
* @param src 源
* @param length 补充到的长度
* @param paddingType 1:补0 2:补空格
* @param leftOrRight 1:左补 2:右补
* @return
*/
public static String padding(String src , int length , int paddingType , int leftOrRight){
String padddingStr = null;
StringBuffer buffer = new StringBuffer(src);
if(paddingType == 1){
padddingStr = "0";
}else{
padddingStr = " ";
}
while(buffer.length() < length){
if(leftOrRight == 1){
buffer.insert(0, padddingStr);
}else{
buffer.append(padddingStr);
}
}
return buffer.toString();
}
/**
* 个人标识码(PIN)加密
* @param pin 6-12个数 不在此范围内返回空
* @param dataTwo 2磁道数据
* @return 个人标识码
* @throws UnsupportedEncodingException
*/
public static String getSecPin(String pin , String dataTwo, String key) throws UnsupportedEncodingException{
if(pin.length() >12 || pin.length()<6){
return null;
}
String pinHex = pin;
if(pin.length() >=10){
pinHex = pin.length()+pinHex;
}else{
pinHex = "0"+pin.length()+pinHex;
}
while(pinHex.length()<16){
pinHex +="F";
}
byte[] pinByte = StringUtil.hexToBytes(pinHex);
int dindex = dataTwo.toLowerCase().indexOf("d");
if(dindex < 0){
dindex = dataTwo.length();
}else{
dindex = dataTwo.toLowerCase().indexOf("d");
}
dataTwo = dataTwo.substring(dindex-13,dindex-1);
dataTwo = "0000"+dataTwo;
byte[] panByte = StringUtil.hexToBytes(dataTwo);
byte[] result = new byte[8];
for(int i =0 ; i<result.length ; i++){
result[i] = (byte) (pinByte[i]^panByte[i]);
}
String temp = key.substring(0,16);
String mainkey = ReadConfig.getValue("mainKey");
String decodekey = new String(Base64.decode(mainkey),"utf-8");
String pinkey = StringUtil.desEcb(decodekey, temp, "00", 1);
String checkKey = StringUtil.desEcb(pinkey, "0000000000000000","00",0);
System.out.println("checkKey : "+checkKey+" 9-12字节"+key.substring(16,24));
String passwordo = StringUtil.desEcb(pinkey, StringUtil.byteToHex(result), "00", 0);
return passwordo;
}
public static String byteBufferToString(java.nio.ByteBuffer buffer) {
Charset charset = null;
CharsetDecoder decoder = null;
CharBuffer charBuffer = null;
try {
charset = Charset.forName("UTF-8");
decoder = charset.newDecoder();
charBuffer = decoder.decode(buffer);
return charBuffer.toString();
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
}
public static String byteBufferToString(java.nio.ByteBuffer[] buffer) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < buffer.length; i++) {
sb.append(byteBufferToString(buffer[i]));
}
return sb.toString();
}
/**
* 返回512长度之内的HEX字符串除以2之后的长度,用HEX字符串表示
* 例如传递的字符串长度为280,其16进制长度为140(0x8C),用字符串8c表示
*
* @param strValue
* @return
*/
public static String getStringHexLenWithinByte(String strValue) {
int len = strValue.length() / 2;
String result = Integer.toHexString(len);
if (result.length() == 1) {
result = "0" + result;
}
return result;
}
public static String trimStringBlank(String strValue) {
String result = strValue.trim(); // 去掉左右的空格
String space = " ";
String tabCh = Character.toString((char) 9);
// 去除中间的空格
result = result.replaceAll(space, "");
result = result.replaceAll(tabCh, "");
return result;
}
public static int getHexDataLen(String data) {
String strTemp = data.replaceAll(" ", "");
return strTemp.length();
}
public static String formatHexDataWithSpace(String data) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < data.length(); i++) {
if (i > 0 && (i % 2 == 0)) {
buffer.append(" ");
}
buffer.append(data.charAt(i));
}
return buffer.toString();
}
public static String asciiToHex(String asciiString) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
byte[] buff = asciiString.getBytes();
for (int i = 0; i < buff.length; i++) {
iValue = buff[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
/**
* 以指定的字符编码解析字符串的长度
*
* @param txt
* 要解析的字符串
* @param charset
* 编码
* @return 字符串的长度
*/
public static int getStrLength(String txt, String charset) {
try {
return txt.getBytes(charset).length;
} catch (UnsupportedEncodingException ex) {
return txt.length();
}
}
public static String byteToHex(byte[] buffer, int offset, int len) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
for (int i = offset; i < offset + len; i++) {
iValue = buffer[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String byteToHex(byte[] buffer) {
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
for (int i = 0; i < buffer.length; i++) {
iValue = buffer[i];
if (iValue < 0)
iValue += 256;
hex = Integer.toString(iValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String asciiToHex(byte[] hexBuffer, int iOffset, int iLen) {
StringBuffer hexString = new StringBuffer();
String hex;
int byteValue;
for (int i = iOffset; i < iOffset + iLen; i++) {
byteValue = hexBuffer[i];
if (byteValue < 0) {
byteValue += 256;
}
hex = Integer.toString(byteValue, 16);
if (hex.length() == 1)
hexString.append("0" + hex);
else
hexString.append(hex);
}
return hexString.toString().toUpperCase();
}
public static String intToHex(int value) {
String hex;
hex = Integer.toString(value, 16);
if (hex.length() % 2 != 0) {
hex = "0" + hex;
}
return hex.toUpperCase();
}
public static byte[] intToBytes(int value , int byteSize) {
String hex = StringUtil.Int2HexStr(value, byteSize*2);
return StringUtil.hexToBytes(hex);
}
/**
* @param hex
* 将16进制的ascii 转成中文
* @return
*/
public static String hexToAscii(String hex) {
byte[] buffer = new byte[hex.length() / 2];
String strByte;
for (int i = 0; i < buffer.length; i++) {
strByte = hex.substring(i * 2, i * 2 + 2);
buffer[i] = (byte) Integer.parseInt(strByte, 16);
}
return new String(buffer);
}
/**
* @param hex
* 每两个字节进行处理
* @return
*/
public static byte[] hexToBytes(String hex) {
byte[] buffer = new byte[hex.length() / 2];
String strByte;
for (int i = 0; i < buffer.length; i++) {
strByte = hex.substring(i * 2, i * 2 + 2);
buffer[i] = (byte) Integer.parseInt(strByte, 16);
}
return buffer;
}
/**
* @param hex
* 每两个字节进行处理
* @return
*/
public static byte[] hexToBytesVip(String hex) {
byte[] buffer = hex.getBytes();
byte[] buff = new byte[buffer.length-14];
for(int i=14;i<buffer.length;i++){
buff[i-14] = buffer[i];
}
return buff;
}
public static boolean hasChineseChar(String strValue) {
boolean bResult = false;
byte[] temp = strValue.getBytes();
for (int i = 0; i < strValue.length(); i++) {
if (temp[i] < 0) {
bResult = true;
break;
}
}
return bResult;
}
public static boolean isNull(String value) {
boolean bIsNull = false;
if (value == null) {
bIsNull = true;
return bIsNull;
}
if (value.trim().length() == 0) {
bIsNull = true;
}
return bIsNull;
}
public static String formatWithSpace(String value) {
String formatedValue = value;
String retValue;
// 去掉所有的空格
formatedValue = trimStringBlank(formatedValue);
if (formatedValue.length() % 2 != 0) {
formatedValue = formatedValue + "0";
}
retValue = "";
for (int i = 0; i < formatedValue.length(); i += 2) {
retValue += formatedValue.substring(i, i + 2) + " ";
}
return retValue;
}
public static String formatDateToString(Date date) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
return sdf.format(date);
}
public static String formatDateToString(Date date, String format) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
/**
* 将一个byte数组转换为字符串
*
* @param arr
* 要转换的byte数组
* @return 转换好的字符串,如果数组的length=0,则返回""。
*/
public static String bytetoString(byte[] arr) {
String str = "";
String tempStr = "";
for (int i = 1; i < arr.length; i++) {
tempStr = (Integer.toHexString(arr[i] & 0xff));
if (tempStr.length() == 1) {
str = str + "0" + tempStr;
} else {
str = str + tempStr;
}
}
return str;
}
public static boolean isChineaseLetter(String name) {
Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5]*$");
Matcher isNum = pattern.matcher(name);
if (!isNum.matches()) {
return false;
}
return true;
}
/**
* 获取字符串的长度,如果有中文,则每个中文字符计为2位
*
* @param value
* 指定的字符串
* @return 字符串的长度
*/
public static int length(String value) {
int valueLength = 0;
String chinese = "[\u0391-\uFFE5]";
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
for (int i = 0; i < value.length(); i++) {
/* 获取一个字符 */
String temp = value.substring(i, i + 1);
/* 判断是否为中文字符 */
if (temp.matches(chinese)) {
/* 中文字符长度为2 */
valueLength += 2;
} else {
/* 其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;
}
public static String formatDateToEngString(Date date) {
if (date == null)
return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
public static String splitAndFilterString(String input, int length) {
if (input == null || input.trim().equals("")) {
return "";
}
// 去掉所有html元素,
String str = input.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll(
"<[^>]*>", "");
str = str.replaceAll("[(/>)<]", "");
int len = str.length();
if (len <= length) {
return str;
} else {
str = str.substring(0, length);
str += "......";
}
return str;
}
/**
* 将字符串格式化为指定的长度整数倍,不足填充对齐
*
* @param data
* @param len
* @param fill
* @return
*/
public static String formatStringByLen(String data, int len, String fill) {
String strData = trimStringBlank(data);
int iFilledLen = strData.length() % len;
if (iFilledLen > 0) {
for (int i = 0; i < 8 - iFilledLen; i++) {
strData += fill;
}
}
return strData;
}
/**
* BCD字符串转换成byte数组
*
* @param data
* @return
*/
public static byte[] bcdToBytes(String data) {
String strData = trimStringBlank(data).toUpperCase();
String str;
int value;
int j = 0;
byte[] bData = new byte[strData.length() / 2];
for (int i = 0; i < strData.length(); i++) {
value = Character.digit(strData.charAt(i), 16);
bData[j] = (byte) ((value << 4) & 0xF0);
value = Character.digit(strData.charAt(i + 1), 16);
bData[j] |= (byte) (value & 0x0F);
i++;
j++;
}
return bData;
}
public static String getSeperatedPathFromPackage(String rootPackage) {
String path = rootPackage.replaceAll("\\.", "\\" + File.separator);
if (!path.endsWith(File.separator)) {
path += File.separator;
}
return path;
}
/**
* @param data
* byte 0x 01
* @return 01
*/
public static String byteToHexStr(byte data) {
String result = Integer.toString((data & 0xff) + 0x100, 16)
.substring(1);
return result;
}
/**
* 将整数转为16进行数后并以指定长度返回(当实际长度大于指定长度时只返回从末位开始指定长度的值)
*
* @param val
* int 待转换整数
* @param len
* int 指定长度
* @return String
*/
public static String Int2HexStr(int val, int len) {
String result = Integer.toHexString(val).toUpperCase();
int r_len = result.length();
if (r_len > len) {
return result.substring(r_len - len, r_len);
}
if (r_len == len) {
return result;
}
StringBuffer strBuff = new StringBuffer(result);
for (int i = 0; i < len - r_len; i++) {
strBuff.insert(0, '0');
}
return strBuff.toString();
}
public static String ucs2Decode(byte[] btsrc) {
if (btsrc == null || btsrc.length == 0) {
return "";
}
String retstr = "";
int nLen = (int) btsrc.length;
byte[] bt;
try {
if (btsrc[0] == (byte) 0x80) {
bt = new byte[nLen - 1];
System.arraycopy(btsrc, 1, bt, 0, nLen - 1);
retstr = (new String(bt, "UTF-16BE"));
} else {
bt = new byte[nLen];
System.arraycopy(btsrc, 0, bt, 0, nLen);
retstr = (new String(bt, "ISO-8859-1"));
}
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
return retstr;
}
public static void BytesCopy(byte[] dest, byte[] source, int offset1,
int offset2, int len) {
for (int i = 0; i < len; i++) {
dest[offset1 + i] = source[offset2 + i];
}
}
}
发表评论
-
java 类的加载 以及 ClassLoader
2020-04-16 09:43 504Class Loader 类加载器: 类加载器负责加载 ... -
Stack 的实现原理深入剖析
2020-04-06 13:26 508Stack 介绍: Stack是栈。 ... -
Vector 的实现原理深入剖析
2020-04-06 13:17 380Vector介绍: Vector 是矢量队列,它是JDK1. ... -
JDK 分析工具
2020-04-05 17:30 415常用分析工具: jps:显示指定系统中所有的HotSpot虚 ... -
二叉树的深度优先遍历和广度优先遍历
2020-03-10 09:33 648概述: 1、深度优先遍历(Depth-First-Sear ... -
Hashtable 的实现原理深入剖析
2020-02-18 20:59 604一、Hashtable的基本方法: 1、定义: HashT ... -
jdk 1.8 新特性
2020-02-17 13:43 4131、default关键字 ... -
Java IO 架构
2019-11-11 16:39 365主要两类: 磁盘I/O 网络I/O 基于字节 ... -
Java 数据结构与算法
2019-04-03 10:25 541程序=数据结构+算法 ... -
Java语言异常(Exception)
2018-10-09 11:40 569异常,是Java中非常常用 ... -
Java并发问题--乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
2018-08-17 09:47 1492首先介绍一些乐观锁与 ... -
Java 高性能编程注意事项
2016-11-17 09:55 6611. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担, ... -
Netty 解析
2017-03-07 13:47 1236Linux网络IO模型: Linux ... -
2016年Java 面试题总结
2016-01-18 13:34 54821多线程、并发及线程的基础问题: 1)Java 中能创建 vo ... -
java 内存模型
2015-12-29 13:44 829JAVA内存模型: Java内存 ... -
JVM 深入剖析
2015-12-29 12:51 1112JVM是JAVA虚拟机(JAVA Virtual Machin ... -
Java 并发编程_Synchronized
2015-12-16 12:42 891硬件的效率和一致性: 由于计算机的运算速度和它的存储和通讯子 ... -
Java 并发编程_Volatile
2015-12-15 13:42 632术语定义: 共享变量:在多个线程之间能够被共享的变量被称为共 ... -
Java 并发编程_ConcurrentLinkedQueue
2015-12-15 13:32 935ConcurrentLinkedQueue 的分析和使用: ... -
Java 并发编程_ConcurrentHashMap
2015-11-10 11:30 849ConcurrentHashMap 的分析和 ...
相关推荐
java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密方法 java Md5加密...
java Md5加密方法 java Md5加密方法java Md5加密方法 java Md5加密方法java Md5加密方法 java Md5加密方法java Md5加密方法 java Md5加密方法java Md5加密方法 java Md5加密方法java Md5加密方法 java Md5加密方法...
C# MD5加密类型支持:1-16位的加密;2-32位加密;3:base64加密对应JAVA md5 16位的加密;2-32位加密;3:base64加密
Java Md5加密工具类
java md5 加密后转为16进制
2. **Java中的MD5加密**:在Java中,可以使用`java.security.MessageDigest`类来实现MD5加密。首先,需要创建一个MD5实例,然后更新要加密的字节数组,最后获取并转换成十六进制字符串。 ```java import java....
Java工具类,它不仅实现了MD5加密,更创新性地接纳String... inputStrs,让你能一次性加密多个字符串。 1. 一键加密,多值无忧 告别繁杂,拥抱简洁。我们的Java MD5加密工具类以String... inputStrs为武器,打破了...
java实现md5 加密解密(在网络中MD5是著名的不可逆算法,但是如果知道MD5的加密的字符串 则可以通过自己的加密算法对明文进行加密,对加密后的密文与字符串匹配; 匹配成功,表示找到明文;但是此程序的时间耗费较高!仅...
java实现MD5加密解密算法,java源代码~
java与c#MD5加密方法得到不一致解决办法,MD5加密后得到不一致结果
js java MD5加密 解决中文不一致问题 验签 只有英文 数字的可以忽略了
下面我们将详细讨论Java中MD5加密的原理、使用场景以及如何实现。 MD5加密的基本原理: MD5算法是一种非对称的加密算法,它将输入的信息通过一系列复杂的数学运算,最终得到一个128位的摘要信息,通常以32位的16...
java中的md5加密函数,已经封装成类和函数了,非常好用。
下面是一个简单的Java MD5加密的代码示例,对应于你提供的`TestMD5.java`文件: ```java import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class TestMD5 { public ...
### JAVA_对文件进行MD5加密 在计算机科学与信息安全领域中,MD5(Message-Digest Algorithm 5)是一种广泛使用的散列函数,能够将任意长度的数据映射为一个固定长度(通常是128位)的十六进制数值。这种算法在数据...
2. **Java中的`java.security.MessageDigest`类**:这是Java标准库提供的用于计算各种消息摘要(包括MD5)的核心类。通过实例化`MessageDigest`并调用其`getInstance("MD5")`方法,我们可以获取一个MD5实例。 3. **...
纯JAVA的MD5加密,利用MD5单向函数产生密钥,方便测试
MD5加密jar包是将MD5算法封装到Java程序中的库,方便开发者在Java应用中快速实现MD5加密功能。 MD5的特点: 1. **不可逆性**:MD5算法是单向的,即给定一个输入,可以得到一个固定长度的摘要,但不能通过摘要反推出...
能直接在java的应用程序中使用的MD5加密实现的jar包, 调用方法:转化成MD5:MD5.getEncryptedPwd(user.getPassword()) MD5验证:MD5.validPassword(password, user.getPassword())
java中常用的工具类,用于MD5的加密,里面还有切割了MD5加密的长度,有DES加密与解密,并且配有main函数可测试,可以根据自己的实际情况使用main函数测试使用