A
Al Murphy
Folks,
I've written a SHA1 hasher that outputs in hexadecimal. Only problem
is though - it needs testing. But how can I be sure?
INPUT OUTPUT
password123 -3402539ff706354bf7c87b342e78b0899e72d569
Is this correct?
Can you have a look at the code below and let me know what you think?
Thanks,
Al.
*****CODE AS FOLLOWS*******
public void makeSHAHash()
{
strInput = jtfInput.getText();
try
{
// Generates a MessageDigest object that implements the SHA1 digest
algorithm
MessageDigest md = MessageDigest.getInstance("SHA");
// Resets the digest for further use
md.reset();
// copnvert the
byte[] buffer = strInput.getBytes();
// Updates the digest using the specified array of bytes
md.update(buffer);
// Completes the hash computation by performing final operations such
as padding
byte[] digest = md.digest();
// Convert the byte array to hexadecimal format
BigInteger bi = new BigInteger(digest);
String strHex = bi.toString(16);
jtfOutput.setText(strHex);
repaint();
}
catch(NoSuchAlgorithmException nsae)
{
nsae.printStackTrace();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
}// end makeSHA1Hash
I've written a SHA1 hasher that outputs in hexadecimal. Only problem
is though - it needs testing. But how can I be sure?
INPUT OUTPUT
password123 -3402539ff706354bf7c87b342e78b0899e72d569
Is this correct?
Can you have a look at the code below and let me know what you think?
Thanks,
Al.
*****CODE AS FOLLOWS*******
public void makeSHAHash()
{
strInput = jtfInput.getText();
try
{
// Generates a MessageDigest object that implements the SHA1 digest
algorithm
MessageDigest md = MessageDigest.getInstance("SHA");
// Resets the digest for further use
md.reset();
// copnvert the
byte[] buffer = strInput.getBytes();
// Updates the digest using the specified array of bytes
md.update(buffer);
// Completes the hash computation by performing final operations such
as padding
byte[] digest = md.digest();
// Convert the byte array to hexadecimal format
BigInteger bi = new BigInteger(digest);
String strHex = bi.toString(16);
jtfOutput.setText(strHex);
repaint();
}
catch(NoSuchAlgorithmException nsae)
{
nsae.printStackTrace();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
}// end makeSHA1Hash