Re:Creating a SHA Password for LDAP

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re:Creating a SHA Password for LDAP

Andrew Petro

Among the channels in Toro (free and open source software for use with uPortal derived from the Academus product) is a channel for changing one's LDAP-stored password.

You may find this additional code example helpful.


Angel Q wrote:
Hello Everyone,

I think this might not be directly relatied to this list, but I know someone will know how to help me :)

I am building a class to add users to my LDAP and I am not managing to SHA the password correctly.

These are the 2 options I have tryed:
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] raw = md.digest();
            BASE64Encoder encoder = new BASE64Encoder();          
            String SHAPassword = encoder.encode(raw);

and the second option I took directly from the CAS code
    private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
   public String encode(final String password) {
        if (password == null) {
            return null;

        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA1");

            final byte[] digest = messageDigest.digest();

            return getFormattedText(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new SecurityException(e);
    private String getFormattedText(byte[] bytes) {
        final StringBuilder buf = new StringBuilder(bytes.length * 2);

        for (int j = 0; j < bytes.length; j++) {
            buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
            buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
        return buf.toString();

/************* END OF CODE ************/

Thank you in advanced for your help,


¿Chef por primera vez? - Sé un mejor Cocinillas.
Entra en Yahoo! Respuestas.

_______________________________________________ Yale CAS mailing list [hidden email]

You are currently subscribed to [hidden email] as: [hidden email]
To unsubscribe, change settings or access archives, see