答案 0 :(得分:0)
使用您自己的示例,使用这样的静态方法创建一个Utility Hashing类...
public class MD5Util {
private static final String ALGORITHM = "MD5";
public static String getHash(String text){
try {
MessageDigest md = MessageDigest.getInstance(ALGORITHM);
md.update(text.getBytes());
byte[] byteData = md.digest();
StringBuffer hexString = new StringBuffer();
for(byte bd : byteData){
String hex = Integer.toHexString(bd & 0xff);
if(hex.length() == 1)
hexString.append(0);
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(MD5Util.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
然后,调用该静态方法并将结果设置为Label字段,如下所示......
hashValueLabel.setText(MD5Util.getHash(textInputLabel.getText()));