Hi there I want to translate the following code to javascript or at least get it explained a bit.
I wanted to use JSweet but I get an error that this:
Line 4: package org.apache.commons.logging does not exist Line 5: package org.apache.commons.logging does not exist
doesnt exist so I cant continue.
Below is the Java Code its a md5 hash function but there are parts that I just dont get ( for example the if check inside the m52hexString function.
`package org.jsweet;
import java.security.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author root
*/
public class ToolBox {
private static Log logging = LogFactory.getLog( ToolBox.class );
public static byte[] md5sum(byte[] org) {
byte md5[] = null;
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (java.security.NoSuchAlgorithmException nse) {
logging.error( "", nse );
return "".getBytes();
}
md5 = md.digest(org);
return md5;
}
public static String md5hexString(String org) {
return ToolBox.md52hexString(ToolBox.md5sum(org.getBytes()));
}
public static String md52hexString(byte[] org) {
int leng = org.length;
StringBuffer strb = new StringBuffer();
for (int count = 0; count < leng; count++) {
int value = (org[count] & 0x7F) + (org[count] < 0 ? 128 : 0);
if (value<16) {
strb.append("0"+Integer.toHexString(value));
} else {
strb.append(Integer.toHexString(value));
}
}
return strb.toString();
}
/** Creates a new instance of ToolBox */
public ToolBox() {
}
}`
Hi there I want to translate the following code to javascript or at least get it explained a bit.
I wanted to use JSweet but I get an error that this:
Line 4: package org.apache.commons.logging does not exist Line 5: package org.apache.commons.logging does not exist
doesnt exist so I cant continue.Below is the Java Code its a md5 hash function but there are parts that I just dont get ( for example the if check inside the m52hexString function.