我在jdk 1.4而不是jdk 1.6中编译应用程序时遇到问题。
String encryptedString = null;
byte[] bytesToBeEncrypted;
try {
// convert string to bytes using a encoding scheme
bytesToBeEncrypted = ren_pass.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] theDigest = md.digest(bytesToBeEncrypted);
// convert each byte to a hexadecimal digit
Formatter formatter = new Formatter();
for (int i = 0; i <= theDigest.length; i++) {
byte b = theDigest[i];
//for (byte b : theDigest) {
formatter.format("%02x", b); // error on this statement b cannot find symbol
}
encryptedString = formatter.toString().toLowerCase();
System.out.print(encryptedString);
} catch (UnsupportedEncodingException eq) {
eq.printStackTrace();
} catch (NoSuchAlgorithmException ew) {
ew.printStackTrace();
}
上面的代码在jdk 1.6中工作正常......但不是在jdk 1.4 ...
显示错误符号b未找到...
请给我一些解决方法来纠正它......
答案 0 :(得分:0)
jdk1.4没有java.util.Formatter,你用java.util.logging.Formatter编译代码吗?
请使用Character.forDigit(byteValue,16)代替