Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #3960 - Return hex strings of SHA1 digests
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Feb 15, 2016
1 parent 9891d0e commit 7d90678
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,16 @@ private String encodeString(String string) {
messageDigest.reset();
messageDigest.update(string.getBytes("UTF-8"));
byte[] bytes = messageDigest.digest();
return new String(bytes);

// Get the Hex version of the digest
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append( String.format("%02X", b) );
}
String hex = sb.toString();
Log.d(TAG, "original = " + string + "; hex = " + hex);

return hex;
}
} catch (Exception e) {
Log.w(TAG, "Error encoding string, will return in original form." + e);
Expand Down

0 comments on commit 7d90678

Please sign in to comment.