java - FileNotFoundException (sunrsasing.jar) -
i'm translating api php java, i've wrote following code emulate sha1 method php. problem when creates new formatter object, filenotfoundexception, debugging found out couldn't find "sunrsasing.jar", looking through stackoverflow found:
which i'm reading before jdk5, in separate jar provided sun mentioned. after that, distributed part of jdk, , not separate jar. blockquote
so question is, there way can fix error other copy & paste jar other source? if not, can 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(); (byte b : hash) { formatter.format("%02x", b); } string result = formatter.tostring(); formatter.close(); return result; }
java.util.formatter
available since java 5, guess using older version. better compatibility can use different implementation of bytetohex()
method thst doesn't need class. see example how convert byte array hex string in java?.
Comments
Post a Comment