Created
May 29, 2013 14:31
-
-
Save darranl/5670712 to your computer and use it in GitHub Desktop.
Digest Code Snippets
This file contains 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
private byte[] createHA1(final byte[] userName, final Account account, final MessageDigest digest, | |
final DigestAlgorithm digestAlgorithm) throws AuthenticationException { | |
if (plainTextPasswords) { | |
char[] attribute = (char[]) account.getAttribute(Account.PLAINTEXT_PASSWORD_ATTRIBUTE); | |
if(attribute == null) { | |
return null; | |
} | |
byte[] password = new String(attribute).getBytes(UTF_8); | |
try { | |
digest.update(userName); | |
digest.update(COLON); | |
digest.update(realmBytes); | |
digest.update(COLON); | |
digest.update(password); | |
return HexConverter.convertToHexBytes(digest.digest()); | |
} finally { | |
digest.reset(); | |
} | |
} else { | |
byte[] preHashed = (byte[])account.getAttribute(Account.DIGEST_HA1_HASH_ATTRIBUTE_PREFIX + digestAlgorithm.getToken()); | |
if(preHashed == null) { | |
return null; | |
} | |
return HexConverter.convertToHexBytes(preHashed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment