这是我的代码,我在字节编码方面遇到了问题。当我得到明文字符串并对其进行哈希处理并尝试打印出结果时,它会变得一团糟。例如,对于plaintext = "hi",它会打印出: hash: ?????????1?W?p????=?????&
公共类 HASHME {
private String hash;
private String salt;
public HASHME(String plaintext) 
{
    try {
    System.setProperty("file.encoding", "UTF-8");
    salt = "salt";
    plaintext = plaintext + salt;
    byte[] bytesOfPlain = plaintext.getBytes("UTF8");
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    byte[] hashedBytes = md.digest(bytesOfPlain);
    hash = new String(hashedBytes, "UTF8");
    System.out.println("hash: " + hash);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}