why is a minus sign prepended to my biginteger?
Posted
by
kyrogue
on Stack Overflow
See other posts from Stack Overflow
or by kyrogue
Published on 2011-01-08T08:34:26Z
Indexed on
2011/01/08
8:54 UTC
Read the original article
Hit count: 251
java
package ewa;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.math.BigInteger;
/**
*
* @author Lotus
*/
public class md5Hash {
public static void main(String[] args) throws NoSuchAlgorithmException {
String test = "abc";
MessageDigest md = MessageDigest.getInstance("MD5");
try {
md.update(test.getBytes("UTF-8"));
byte[] result = md.digest();
BigInteger bi = new BigInteger(result);
String hex = bi.toString(16);
System.out.println("Pringting result");
System.out.println(hex);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(md5Hash.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
i am testing conversion of byte to hex and when done, the end result has a minus sign on the beginning of the string, why does this happen? i have read the docs and it says it will add a minus sign, however i do not understand it. And will the minus sign affect the hash result? because i am going to implement it to hash password stored on my database
© Stack Overflow or respective owner