Created
April 5, 2013 13:40
-
-
Save BartoszJarocki/433093323d41600d3fb4 to your computer and use it in GitHub Desktop.
sha256
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
public static String getMD5Hash(String password) { | |
try { | |
final MessageDigest messageDigest = MessageDigest.getInstance(MD5); | |
messageDigest.reset(); | |
messageDigest.update(password.getBytes(UTF_8)); | |
final byte[] resultByte = messageDigest.digest(); | |
final String result = new String(Hex.encodeHex(resultByte)); | |
Log.d(TAG, "Password MD5 hash: " + result); | |
return result; | |
} catch (NoSuchAlgorithmException e) { | |
Log.d(TAG, e.toString()); | |
} catch (UnsupportedEncodingException e) { | |
Log.d(TAG, e.toString()); | |
} | |
return null; | |
} | |
public static String getSha256(String message) { | |
try { | |
MessageDigest md = MessageDigest.getInstance(SHA256); | |
md.reset(); | |
md.update(message.getBytes(UTF_8)); | |
byte[] digest = md.digest(); | |
final String result = new String(Hex.encodeHex(digest)); | |
Log.d(TAG, "HMAC after Sha256 encoding: " + result); | |
return result; | |
} catch (NoSuchAlgorithmException e) { | |
Log.d(TAG, e.toString()); | |
} catch (UnsupportedEncodingException e) { | |
Log.d(TAG, e.toString()); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment