- Rename HashResult to EncryptedPassword to reflect its broader use - Use EncryptedPassword in methods that require the hash and the salt, instead of passing them as strings separately - Store EncryptedPassword as field in PlayerAuth; updatePassword() thus processes the entire data in the EncryptedPassword object
39 lines
1.5 KiB
Java
39 lines
1.5 KiB
Java
package fr.xephi.authme.security.crypts;
|
|
|
|
import fr.xephi.authme.security.HashUtils;
|
|
import fr.xephi.authme.security.MessageDigestAlgorithm;
|
|
import fr.xephi.authme.security.crypts.description.Usage;
|
|
import fr.xephi.authme.security.crypts.description.Recommendation;
|
|
import fr.xephi.authme.security.crypts.description.SaltType;
|
|
import fr.xephi.authme.security.crypts.description.HasSalt;
|
|
|
|
import java.nio.charset.Charset;
|
|
import java.security.MessageDigest;
|
|
|
|
@Recommendation(Usage.DO_NOT_USE)
|
|
@HasSalt(SaltType.USERNAME)
|
|
public class CRAZYCRYPT1 extends UsernameSaltMethod {
|
|
|
|
private static final char[] CRYPTCHARS =
|
|
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
private final Charset charset = Charset.forName("UTF-8");
|
|
|
|
private static String byteArrayToHexString(final byte... args) {
|
|
final char[] chars = new char[args.length * 2];
|
|
for (int i = 0; i < args.length; i++) {
|
|
chars[i * 2] = CRYPTCHARS[(args[i] >> 4) & 0xF];
|
|
chars[i * 2 + 1] = CRYPTCHARS[(args[i]) & 0xF];
|
|
}
|
|
return new String(chars);
|
|
}
|
|
|
|
@Override
|
|
public EncryptedPassword computeHash(String password, String name) {
|
|
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
|
|
final MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.SHA512);
|
|
md.update(text.getBytes(charset), 0, text.length());
|
|
return new EncryptedPassword(byteArrayToHexString(md.digest()));
|
|
}
|
|
|
|
}
|