Created
November 22, 2011 09:09
-
-
Save bosmievoll/1385255 to your computer and use it in GitHub Desktop.
Active Directory Password Encoder
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
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