forked from nailperry-zd/LazierTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
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
zhangdan
committed
Mar 8, 2018
1 parent
92d45b9
commit e847018
Showing
8 changed files
with
233 additions
and
37 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
49 changes: 49 additions & 0 deletions
49
tracker/src/main/java/com/codeless/tracker/utils/StringEncrypt.java
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.codeless.tracker.utils; | ||
|
||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
/** | ||
* Created by zhangdan on 16/12/26. | ||
*/ | ||
|
||
public class StringEncrypt { | ||
public static final String DEFAULT = "SHA-256"; | ||
/** | ||
* Encrypting the string. Algorithms such as MD5, SHA-1, SHA-256; default SHA-256. | ||
* | ||
* @param strSrc the string to be Encrypted | ||
* @param encName Algorithm for Encryption | ||
* @return | ||
*/ | ||
public static String Encrypt(String strSrc, String encName) { | ||
MessageDigest md = null; | ||
String strDes = null; | ||
|
||
byte[] bt = strSrc.getBytes(); | ||
try { | ||
if (encName == null || encName.equals("")) { | ||
encName = "SHA-256"; | ||
} | ||
md = MessageDigest.getInstance(encName); | ||
md.update(bt); | ||
strDes = bytes2Hex(md.digest()); // to HexString | ||
} catch (NoSuchAlgorithmException e) { | ||
return null; | ||
} | ||
return strDes; | ||
} | ||
|
||
public static String bytes2Hex(byte[] bts) { | ||
String des = ""; | ||
String tmp = null; | ||
for (int i = 0; i < bts.length; i++) { | ||
tmp = (Integer.toHexString(bts[i] & 0xFF)); | ||
if (tmp.length() == 1) { | ||
des += "0"; | ||
} | ||
des += tmp; | ||
} | ||
return des; | ||
} | ||
} |
Oops, something went wrong.