mirror of
https://e.coding.net/circlecloud/AuthMe.git
synced 2025-11-26 21:46:23 +00:00
28
src/main/java/fr/xephi/authme/security/crypts/SHA256.java
Normal file
28
src/main/java/fr/xephi/authme/security/crypts/SHA256.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class SHA256 implements EncryptionMethod {
|
||||
|
||||
private static String getSHA256(String message) throws NoSuchAlgorithmException {
|
||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
||||
sha256.reset();
|
||||
sha256.update(message.getBytes());
|
||||
byte[] digest = sha256.digest();
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException {
|
||||
String[] line = hash.split("\\$");
|
||||
return hash.equals(getHash(password, line[2], ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
|
||||
return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user