1 package org
.argeo
.security
;
3 import org
.apache
.commons
.codec
.DecoderException
;
4 import org
.apache
.commons
.codec
.binary
.Base64
;
5 import org
.apache
.commons
.codec
.binary
.Hex
;
6 import org
.springframework
.security
.providers
.ldap
.authenticator
.LdapShaPasswordEncoder
;
8 public class PasswordSandbox
{
9 public static void main(String
[] args
) {
12 String pwdPlain
= "demo";
14 // Check Java generated values
15 LdapShaPasswordEncoder lspe
= new LdapShaPasswordEncoder();
16 String pwdLdapShaBase64
= lspe
.encodePassword(pwdPlain
, null);
17 System
.out
.println("pwdLdapShaBase64:\t\t" + pwdLdapShaBase64
);
19 String pwdShaBase64
= pwdLdapShaBase64
.substring("{SHA}".length());
20 System
.out
.println("pwdShaBase64:\t\t\t" + pwdShaBase64
);
22 byte[] pwdShaArray
= Base64
.decodeBase64(pwdShaBase64
.getBytes());
23 String pwdShaHex
= new String(Hex
.encodeHex(pwdShaArray
));
24 System
.out
.println("pwdShaHex:\t\t\t" + pwdShaHex
);
26 // Check that we can use JavaScript generated values in Hex
27 String jsShaHex
= "89e495e7941cf9e40e6980d14a16bf023ccd4c91";
28 System
.out
.println("jsShaHex:\t\t\t" + pwdShaHex
);
29 System
.out
.println("pwdShaHex==jsShaHex:\t\t"
30 + (pwdShaHex
.equals(jsShaHex
)));
32 byte[] jsShaArray
= Hex
.decodeHex(jsShaHex
.toCharArray());
33 String jsShaBase64
= new String(Base64
.encodeBase64(jsShaArray
));
34 System
.out
.println("jsShaBase64:\t\t\t" + jsShaBase64
);
35 System
.out
.println("pwdShaBase64==jsShaBase64:\t"
36 + (pwdShaBase64
.equals(jsShaBase64
)));
37 } catch (DecoderException e
) {