Created
December 24, 2012 23:52
-
-
Save volgar1x/4371068 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NotNull | |
@Override | |
public User find(byte[] bytes) { | |
byte[] decrypted; | |
try { | |
decrypted = decrypter.doFinal(bytes); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
StringBuilder salt = new StringBuilder(), | |
username = new StringBuilder(), | |
password = new StringBuilder(); | |
int username_length = 0; | |
// ojagawgiqxtawwicppjbzhteloapxhwp\u0006foobarbuzz | |
// [salt:32] [username_length:1] [username:username_length] [password:-1] | |
for (int i = 0; i < decrypted.length; ++i) { | |
if (i < 32) { // first 32 characters are the salt | |
salt.append((char) decrypted[i]); | |
} else if (i == 32) { // 33rd byte is username's length | |
username_length = decrypted[i]; | |
} else if (i <= 32 + username_length) { // next characters are the username | |
username.append((char) decrypted[i]); | |
} else { // remaining characters are the password | |
password.append((char) decrypted[i]); | |
} | |
} | |
return authenticate(username.toString(), password.toString(), salt.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment