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");
md.update(this.password.getBytes());
byte[] raw = md.digest();
BASE64Encoder encoder = new BASE64Encoder();
String SHAPassword = encoder.encode(raw);
and the second option I took directly from the CAS code
org.jasig.cas.authentication.handler.DefaultPasswordEncoder.java
:
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");
messageDigest.update(password.getBytes());
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,
Angel
______________________________________________
¿Chef por primera vez?
Sé un mejor Cocinillas.
http://es.answers.yahoo.com/info/welcome_______________________________________________
Yale CAS mailing list
[email protected]
http://tp.its.yale.edu/mailman/listinfo/cas