0

I am using Md5 for sharedpref now when I get the data shared but see encrypted it

 public static String md5(final String s) {
    final String MD5 = "MD5";
    try {
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest
                .getInstance(MD5);
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

this codes for get the data from shared, I can not see data, i only see the encripted md5

 sharedPreferences=getSharedPreferences(nameshe,MODE_PRIVATE);
        String  nam=sharedPreferences.getString(sa,"jan");
        String names =md5(nam);
        textView.setText(names);
Amjad Alwareh
  • 2,926
  • 22
  • 27
  • To understand your question, you want to decrypt your code when you pull it out of SharedPreferences? Because if you encrypted it when you put it inside SharedPreferences, it will be encrypted when you pull it out. – tomerpacific May 03 '20 at 06:22
  • Yes I want decrypt your code when you pull it out of SharedPreferences – David Haye May 03 '20 at 06:27
  • 2
    MD5 is a hashing algorithm and and not an encryption algorithm. Therefore, you cannot convert it back to the original value. You might want to consider a different method for your needs. – tomerpacific May 03 '20 at 06:54
  • You can tell me different method for encryption ? – David Haye May 03 '20 at 07:18
  • [This](https://stackoverflow.com/questions/6788018/android-encryption-decryption-using-aes) is an example – tomerpacific May 03 '20 at 07:35

0 Answers0