It seems that this extension doesn't show the first zeros.
I just have tried on SHA512
For instance :
SHA512("155") 's length is 126
SHA512("149") 's length is 127
The length of 90% of them are 128
The parameter given to the .toString() method defines the radix, here 16 since we want an hexadecimal representation.
However this method has no clue about how many numbers it should consider. As we know integer numbers never have useless zeros at their beginning (this is precisely the difference with strings). Consequently if the hash begins with one or several zeros, they won't be converted to text and they will be missing in the string.
Solution: we should define for each algorithm the number of characters expected for the hash this algorithm will return (example: 32 characters for MD5). Then instead of returning "number.toString(16)", we should check and add the number of missing zeros at the beginning of the string to reach the expected length.
Be aware that we face the same problem with the GetFileHash() function:
publicStringGetFileHash(Stringfilename,Stringalgorithm){
try{
MessageDigestdigest=MessageDigest.getInstance(algorithm);InputStreamis=newFileInputStream(newFile(filename));byte[]buffer=newbyte[8192];intread=0;Stringoutput=null;try{
while((read=is.read(buffer))>0){
digest.update(buffer,0,read);}
byte[]md5sum=digest.digest();BigIntegerbigInt=newBigInteger(1,md5sum);output=bigInt.toString(16);}
catch(IOExceptione){
thrownewRuntimeException("Não foi possivel processar o arquivo.",e);}
finally{
try{
is.close();}
catch(IOExceptione){
thrownewRuntimeException("Não foi possivel fechar o arquivo",e);}
}
returnoutput;}
catch(FileNotFoundExceptione){}
catch(NoSuchAlgorithmExceptione){}
return"";
}
I've never coded in Java nor in oriented object paradigm so I will let someone else write the right code for the time being.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The GetTextHash() function is:
The parameter given to the .toString() method defines the radix, here 16 since we want an hexadecimal representation.
However this method has no clue about how many numbers it should consider. As we know integer numbers never have useless zeros at their beginning (this is precisely the difference with strings). Consequently if the hash begins with one or several zeros, they won't be converted to text and they will be missing in the string.
Solution: we should define for each algorithm the number of characters expected for the hash this algorithm will return (example: 32 characters for MD5). Then instead of returning "number.toString(16)", we should check and add the number of missing zeros at the beginning of the string to reach the expected length.
Be aware that we face the same problem with the GetFileHash() function:
I've never coded in Java nor in oriented object paradigm so I will let someone else write the right code for the time being.