I am quite new in Android development and hereby I would like to ask you for some help. Basically I have created the text fields of a Android Log-in page (username field & password field) and it works well without hashing a password. But now I want to use SHA256. My knowledge is still not enough to put those two together. So as follows:
public static String SHA256 (String text) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(text.getBytes());
byte[] digest = md.digest();
String hashedpass = Base64.encodeToString(digest, Base64.DEFAULT);
}
private JSONObject buidJsonObject() throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("Username", etName.getText().toString()); // <- here I get directly what I have typed in
jsonObject.accumulate("Password", hashedpass); // <- here I want to have it hashed with SHA256.
return jsonObject;
}
Could you help me with these? Thank you