How to decrypt encrypted email in SHA-256?

Asked

Viewed 769 times

1

I’m encrypting an email and saving it in the bank, how do I decrypt that same encrypted email.

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 that way?

  • 2

    I have the impression that you did not encrypt, but rather generated a hash. And hash of this type is made not to be reversible. Usually the hash is used to generate the key that will encrypt the message, and not to be applied to the message content.

  • 2

    SHA-256 is a hash. It cannot be reversed because that is the nature of a hash.

1 answer

8


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.