Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created December 24, 2012 23:52
Show Gist options
  • Save volgar1x/4371068 to your computer and use it in GitHub Desktop.
Save volgar1x/4371068 to your computer and use it in GitHub Desktop.
@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