Mam problem przy hashowaniu tekstu.
Przy SHA1 wszystko działa, SHA256 juz nie. Nie mam pojęcia dlaczego.
Kod poniżej.
public static String getHash(String message, String algorithm) {
try {
byte[] buffer = message.getBytes();
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(buffer);
byte[] digest = md.digest();
String hexValue = null;
for(int i = 0 ; i < digest.length ; i++) {
int b = digest[i] & 0xff;
if (Integer.toHexString(b).length() == 1) hexValue = hexValue + "0";
hexValue = hexValue + Integer.toHexString(b);
}
return hexValue;
} catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}