Skip to content

Instantly share code, notes, and snippets.

@bosmievoll
Created November 22, 2011 09:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bosmievoll/1385255 to your computer and use it in GitHub Desktop.
Save bosmievoll/1385255 to your computer and use it in GitHub Desktop.
Active Directory Password Encoder
package no.smievoll.ad;
import javax.naming.directory.BasicAttribute;
import java.util.List;
public class ADPasswordEncoder {
private static byte[] generatePasswordByteArray(String clearTextPassword) throws UnsupportedEncodingException {
/* NB: AD requires password string to be quoted. */
return ("\"" + clearTextPassword + "\"").getBytes("UTF-16LE");
}
public static List<BasicAttribute> createAttribute(String clearTextPassword) throws UnsupportedEncodingException {
List<BasicAttribute> pwdAttrs = new ArrayList<BasicAttribute>();
pwdAttrs.add(new BasicAttribute("unicodePwd", generatePasswordByteArray(clearTextPassword)));
return pwdAttrs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment