20 lines
599 B
Java
20 lines
599 B
Java
package xin.merlin.myplayerbackend.utils;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.security.MessageDigest;
|
|
|
|
public class SHA256Util {
|
|
|
|
public static String sha256(String s) {
|
|
try {
|
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
byte[] bytes = md.digest(s.getBytes(StandardCharsets.UTF_8));
|
|
StringBuilder sb = new StringBuilder();
|
|
for (byte b : bytes) sb.append(String.format("%02x", b));
|
|
return sb.toString();
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|