How to decrypt encrypted e-mail on SHA-256?

1

I am encrypting an email and saving it in the database, how do I decrypt the same email that was encrypted.

Follow the code I used to encrypt.

public String getEmailCriptografado(String email){
    email = email.toLowerCase();
    email = Normalizer.normalize(email, Normalizer.Form.NFD);
    Pattern pattern = Pattern.compile("\p{InCombiningDiacriticalMarks}+");
    pattern.matcher(email).replaceAll("");

    String emailCritptografado = "";

    try {
        MessageDigest algoritmo = MessageDigest.getInstance("SHA-256");

        try {
            byte messageDigest[] = algoritmo.digest((email)
                    .getBytes("UTF-8"));
            StringBuilder hexString = new StringBuilder();

            for (byte b : messageDigest) {
                hexString.append(String.format("%02X", 0xFF & b));
            }

            emailCritptografado = hexString.toString();
            System.out.println(emailCritptografado);

        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    return emailCriptografado;
}

Is there any way to decrypt in this way?

    
asked by anonymous 02.03.2016 / 19:17

1 answer

8

Not possible. SHA-256 is a hash function and as such it is "one way", after the conversion there is no back, there is no "decrypt" process. If for some reason you want to encrypt the emails in the bank (this is something very unusual in, see if it is really necessary) you should look for some "two way" encryption function that allows for reversal.

    
02.03.2016 / 19:25