Created
April 13, 2018 12:37
-
-
Save erfanegtfi/a62707696aa9d10af0b187c37670385d to your computer and use it in GitHub Desktop.
Hash String md5, sha1
This file contains hidden or 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
| import android.support.v4.view.MotionEventCompat; | |
| import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; | |
| import java.security.MessageDigest; | |
| import java.security.NoSuchAlgorithmException; | |
| public class Hash { | |
| public static String getHash(String txt, String hashType) { | |
| try { | |
| byte[] array = MessageDigest.getInstance(hashType).digest(txt.getBytes()); | |
| StringBuffer sb = new StringBuffer(); | |
| for (byte b : array) { | |
| sb.append(Integer.toHexString((b & MotionEventCompat.ACTION_MASK) | AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY).substring(1, 3)); | |
| } | |
| return sb.toString(); | |
| } catch (NoSuchAlgorithmException e) { | |
| return null; | |
| } | |
| } | |
| public static String md5(String txt) { | |
| return getHash(txt, "MD5"); | |
| } | |
| public static String sha1(String txt) { | |
| return getHash(txt, "SHA1"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment