This is my code, I am having trouble with byte encoding. When I get the plaintext string, and hash it, and try to print out the result, it gets messed up. For example, for plaintext = "hi", it prints out: hash: ?????????1?W?p????=?????&
public class 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();
}
}