This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
McGamerZone/commons/src/main/java/zone/themcgamer/common/HashUtils.java

30 lines
894 B
Java
Raw Normal View History

2021-02-19 20:11:08 +00:00
package zone.themcgamer.common;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author Braydon
*/
public class HashUtils {
/**
* Encrypt the given {@link String} as SHA-256
2021-05-02 18:54:10 +00:00
*
2021-02-19 20:11:08 +00:00
* @param s the string to encrypt
* @return the encrypted string
*/
public static String encryptSha256(String s) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(s.getBytes());
byte digest[] = messageDigest.digest();
StringBuffer buffer = new StringBuffer();
for (byte b : digest)
buffer.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
return buffer.toString();
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return null;
}
}