I'm translating an api from php to java, i've wrote the following code to emulate sha1 method from php. The problem is that when it creates the new formatter object, I get a FileNotFoundException, debugging I found out that it couldn't find "sunrsasing.jar", looking through stackoverflow I found:
which I'm reading so that before JDK5, it was in a separate jar provided by sun that you mentioned. After that, it was distributed as part of JDK, and not as a separate jar. Blockquote
So my question is, is there any way i can fix the error other than copy & paste the jar from some other source? If not, where can I find it?
private static String encryptPassword(String password)
{
String sha1 = "";
try
{
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(password.getBytes("UTF-8"));
sha1 = byteToHex(crypt.digest());
}
catch(NoSuchAlgorithmException e)
{
e.printStackTrace();
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
return sha1;
}
private static String byteToHex(final byte[] hash)
{
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}