import java.security
I used your code but modified it so I can hash strings and other objects.
public static String getHash(Object o)
{
try
{
MessageDigest mdAlgorithm = MessageDigest.getInstance("MD5");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
mdAlgorithm.update(baos.toByteArray());
byte[] digest = mdAlgorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < digest.length; i++)
{
String x = Integer.toHexString(0xFF & digest[i]);
if (x.length() < 2) x = "0" + x;
hexString.append(x);
}
return(hexString.toString());
}
catch(NoSuchAlgorithmException e) { return(null); }
catch(IOException e) { return(null); }
}
Thanks! This solution saves me some time ;)
<script>
var i=0;
while (var<5)
{
documnet.write("Hello World!");
var=var+1;
}
</script>
Excellent example!
I'm just starting out building Java apps and need to add some authentication.
I decided upon storing user details in a plain text file (college project - simplest option - not allowed to use a DB) and wanted to shadow passwords. Now I can!
nice job!!!
Works like a charm, the solution I was using,
String md5 = new BigInteger( 1, md.digest() ).toString(16);
wanted to truncated leading 0's, this one doesn't.