geforkt von Mirrors/Velocity
Rename some stuff for clarity.
Dieser Commit ist enthalten in:
Ursprung
01f158f193
Commit
66dcb13b5a
@ -17,7 +17,7 @@ public enum EncryptionUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String twosComplementSha1Digest(byte[] digest) {
|
public static String twosComplementHexdigest(byte[] digest) {
|
||||||
return new BigInteger(digest).toString(16);
|
return new BigInteger(digest).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public enum EncryptionUtils {
|
|||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||||
digest.update(sharedSecret);
|
digest.update(sharedSecret);
|
||||||
digest.update(key.getEncoded());
|
digest.update(key.getEncoded());
|
||||||
return twosComplementSha1Digest(digest.digest());
|
return twosComplementHexdigest(digest.digest());
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
|
|
||||||
class EncryptionUtilsTest {
|
class EncryptionUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
void twosComplementSha1Digest() throws Exception {
|
void twosComplementHexdigest() throws Exception {
|
||||||
String notchHash = hexDigest("Notch");
|
String notchHash = mojangLoginSha1("Notch");
|
||||||
assertEquals("4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48", notchHash);
|
assertEquals("4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48", notchHash);
|
||||||
|
|
||||||
String jebHash = hexDigest("jeb_");
|
String jebHash = mojangLoginSha1("jeb_");
|
||||||
assertEquals("-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1", jebHash);
|
assertEquals("-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1", jebHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String hexDigest(String str) throws Exception {
|
private String mojangLoginSha1(String str) throws Exception {
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||||
digest.update(str.getBytes(StandardCharsets.UTF_8));
|
digest.update(str.getBytes(StandardCharsets.UTF_8));
|
||||||
byte[] digested = digest.digest();
|
byte[] digested = digest.digest();
|
||||||
return EncryptionUtils.twosComplementSha1Digest(digested);
|
return EncryptionUtils.twosComplementHexdigest(digested);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren