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?
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.
– Bacco
SHA-256 is a hash. It cannot be reversed because that is the nature of a hash.
– Daniel Omine