Creating SHA-1 Signature

compared with
Current by Kees de Kooter
on Jul 03, 2006 11:19.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (8)

View Page History
h4. The Code
{code}
import java.math.BigInteger;
byte[] hashBytes = messageDigest.digest();

StringBuffer stringBuffer = new StringBuffer();

// Convert digested bytes to string
for (int i = 0; i < hashBytes.length; i++) {
String plainText = Integer.toHexString(0xFF & hashBytes[i]);

if (plainText.length() < 2) stringBuffer.append("0");

BigInteger bigInteger = new BigInteger(hashBytes); stringBuffer.append(plainText);
signature = bigInteger.toString(16); }

signature = stringBuffer.toString();

} catch (NoSuchAlgorithmException e) {
logger.error(e.toString());
}
{code}
h4. References
Online calculation of hashes: http://discodia.org/en/md5