O fato é o seguinte , ta difícil o negocio aqui pra integrar php4 e java !
primeiro foi com o RSA foi dificil ajustar os algoritmos principalmente por causa de charset !
E agora isso !
Usando isso aqui pra calcular o md5 de um arquivo:public static String calculate(String path)
{
String output = new String();
try
{
InputStream is = new FileInputStream(new File(path));
MessageDigest digest = MessageDigest.getInstance("MD5");
DigestInputStream digin = new DigestInputStream(is,digest);
byte[] buffer = new byte[4096];
try{
while ( digin.read(buffer, 0, 4096) != - 1)
{
//Do nothing, the digest is calculated automatically as file is read in.
}
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
output = bigInt.toString(16);
}
catch(Exception e)
{
throw new RuntimeException("Unable to process file for MD5", e);
}
finally
{
try
{
is.close();
}
catch(IOException e)
{
throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
}
}
}
catch(Exception ex){;}
return output;
}
Ele me retorna um md5 diferente do php , porém por incrível que pareça na maioria das vezes os Hashs batem , mas em alguns casos eles diferem ! lendo vi alguma coisa dizendo que pode ter alguma disparidade
nos charsets em sistemas operacionais diferentes ! Mas eu fico meio na duvida pq ambos rodam em win32(windows) .
Eu acredito que o java que ta fazendo coisa errada porque usando o openssl ele tambem me retornou um hash igual ao do php.
Alguma sugestão ?
