Q:

Generate Unique hash from Long id

I need to generate a unique hash from a ID value of type Long. My concern is that it should not globally generate the same hash from two different Long/long values. 
MD5 hashing looks a nice solution but the hash String is very long. I only need characters 
0-9
a-z and A-Z

And just 6-characters like: j4qwO7
What could be the simpliest solution?

A:

Your requirements cannot be met. You've got an alphabet of 62 possible characters, and 6 characters available - which means there are 626 possible IDs of that form.
However, there are 2568 possible long values. By the pigeon-hole principle, it's impossible to give each of those long values a different ID of the given form.

A:

You don't have to use the hex representation. Build your own hash representation by using the actual hash bytes from the function. You could truncate the hash output to simplify the hash representation, but that would make collisions more probable.
Edit:
The other answers stating that what you ask isn't possible, based on the number of possible long values, is teoretically true, if you actually need the whole range.
If your IDs are auto incremented from zero and up, just 62^6 = 56800235584 values might be more than enough for you, depending on your needs.

