Last active
February 7, 2021 03:00
-
-
Save dsdstudio/9094070 to your computer and use it in GitHub Desktop.
java sha-512 encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* sha512 방식으로 암호화한 스트링을 리턴한다 | |
* | |
* @param target | |
* @return [encrypted string] | |
*/ | |
public final static String encryptSHA512(String target) { | |
try { | |
MessageDigest sh = MessageDigest.getInstance("SHA-512"); | |
sh.update(target.getBytes()); | |
StringBuffer sb = new StringBuffer(); | |
for (byte b : sh.digest()) sb.append(String.format("%1$02x", 0xff & b)); | |
return sb.toString(); | |
} catch (NoSuchAlgorithmException e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree with odizapc. Or you can replace this line:
for (byte b : sh.digest()) sb.append(Integer.toHexString(0xff & b));
with this:
for (byte b : sh.digest()) sb.append(String.format("%1$02x", 0xff & b));
After all, thanks to dsdstudio and everyone