Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!