Get hash of a String as String

I'm here:

    String password = "123";
    byte passwordByte[] = password.getBytes();
    MessageDigest md = MessageDigest.getInstance("SHA-512");
    byte passwortHashByte[] = md.digest(passwordByte);

The passwortHashByte-Array contains only a lot of numbers. I want to convernt this numbers to one String which contains the hash-code as plaintext. How i do this?

Jon Skeet
people
quotationmark

I want to convernt this numbers to one String which contains the hash-code as plaintext.

The hash isn't plain-text. It's binary data - arbitrary bytes. That isn't plaintext any more than an MP3 file is.

You need to work out what textual representation you want to use for the binary data. That in turn depends on what you want to use the data for. For the sake of easy diagnostics I'd suggest a pure-ASCII representation - probably either base64 or hex. If you need to easily look at individual bytes, hex is simpler to read, but base64 is a bit more compact.

It's also important to note that MD5 isn't a particularly good way of hashing passwords... and it looks like you're not even salting them. It may be good enough for a demo app which will never be released into the outside world, but you should really look into more secure approaches. See Jeff Atwood's blog post on the topic for an introduction, and ideally get hold of a book about writing secure code.

people

See more on this question at Stackoverflow