Skip to content

Instantly share code, notes, and snippets.

@BartoszJarocki
Created April 5, 2013 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BartoszJarocki/433093323d41600d3fb4 to your computer and use it in GitHub Desktop.
Save BartoszJarocki/433093323d41600d3fb4 to your computer and use it in GitHub Desktop.
sha256
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