]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/test/java/org/argeo/security/PasswordSandbox.java
Fix issues with security dependencies
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / test / java / org / argeo / security / PasswordSandbox.java
1 package org.argeo.security;
2
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;
7
8 public class PasswordSandbox {
9 public static void main(String[] args) {
10 try {
11 // Tested password
12 String pwdPlain = "demo";
13
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);
18
19 String pwdShaBase64 = pwdLdapShaBase64.substring("{SHA}".length());
20 System.out.println("pwdShaBase64:\t\t\t" + pwdShaBase64);
21
22 byte[] pwdShaArray = Base64.decodeBase64(pwdShaBase64.getBytes());
23 String pwdShaHex = new String(Hex.encodeHex(pwdShaArray));
24 System.out.println("pwdShaHex:\t\t\t" + pwdShaHex);
25
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)));
31
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) {
38 e.printStackTrace();
39 }
40
41 }
42
43 }