-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
132 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.fengwenyi.javalib.util; | ||
|
||
/** | ||
* 进制转换工具类 | ||
* @author Wenyi Feng. | ||
*/ | ||
public class HexUtils { | ||
|
||
/** | ||
* 二进制转十六进制 | ||
* @param bytes [ellipsis] | ||
* @return [ellipsis] | ||
*/ | ||
public static String _2_16(byte[] bytes) { | ||
|
||
if (bytes == null || bytes.length == 0) | ||
return null; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (byte aByte : bytes) { | ||
String hex = Integer.toHexString(aByte & 0xFF); | ||
if (hex.length() == 1) { | ||
hex = '0' + hex; | ||
} | ||
sb.append(hex.toUpperCase()); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
|
||
/** | ||
* 16进制转化为 2进制 | ||
* @param hexStr 16进制字符串 | ||
* @return byte[] | ||
*/ | ||
public static byte[] _16_2(String hexStr) { | ||
if (StringUtils.isEmpty(hexStr)) | ||
return null; | ||
|
||
byte[] result = new byte[hexStr.length() / 2]; | ||
for (int i = 0; i < hexStr.length() / 2; i++) { | ||
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); | ||
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); | ||
result[i] = (byte) (high * 16 + low); | ||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.fengwenyi.test; | ||
|
||
import com.fengwenyi.javalib.util.MD5Util; | ||
import org.junit.Test; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
|
||
/** | ||
* @author Wenyi Feng | ||
* @since 2019-01-24 | ||
*/ | ||
public class MD5Test { | ||
|
||
@Test | ||
public void md5() { | ||
String md5Str = null; | ||
try { | ||
md5Str = MD5Util.MD5("12345678"); | ||
} catch (NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
} | ||
System.out.println(md5Str); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters