Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
the enum for encrypt algorithm name in java

I found when I use a algorithm to hash text in java, I have to transfer a const value like SHA-256 into the function like this:

public static String getHashText(String passwordToHash,String algorithm) {
        String generatedPassword = null;
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            byte[] bytes = md.digest(passwordToHash.getBytes(StandardCharsets.UTF_8));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bytes.length; i++) {
                sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
            }
            generatedPassword = sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return generatedPassword;
    }

we should pass the const algorithm name like this:

String hashedRefreshToken = MD5Utils.getHashText(request.getRefresh_token(),"SHA-256");

I was wonder is there a system Enum for the encrypt algorithm so that I could do it like this:

String hashedRefreshToken = MD5Utils.getHashText(request.getRefresh_token(),ENCRYPT.SHA-256);

this would be more readable code, I found a class MessageDigest but that named SHA256 not SHA-256. is there any system enum for it? why did not have enum? why we need to pass a const string into?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda