2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
;
18 import org
.apache
.commons
.codec
.DecoderException
;
19 import org
.apache
.commons
.codec
.binary
.Base64
;
20 import org
.apache
.commons
.codec
.binary
.Hex
;
21 import org
.springframework
.security
.authentication
.encoding
.LdapShaPasswordEncoder
;
23 public class PasswordSandbox
{
24 public static void main(String
[] args
) {
27 String pwdPlain
= "demo";
29 // Check Java generated values
30 LdapShaPasswordEncoder lspe
= new LdapShaPasswordEncoder();
31 String pwdLdapShaBase64
= lspe
.encodePassword(pwdPlain
, null);
32 System
.out
.println("pwdLdapShaBase64:\t\t" + pwdLdapShaBase64
);
34 String pwdShaBase64
= pwdLdapShaBase64
.substring("{SHA}".length());
35 System
.out
.println("pwdShaBase64:\t\t\t" + pwdShaBase64
);
37 byte[] pwdShaArray
= Base64
.decodeBase64(pwdShaBase64
.getBytes());
38 String pwdShaHex
= new String(Hex
.encodeHex(pwdShaArray
));
39 System
.out
.println("pwdShaHex:\t\t\t" + pwdShaHex
);
41 // Check that we can use JavaScript generated values in Hex
42 String jsShaHex
= "89e495e7941cf9e40e6980d14a16bf023ccd4c91";
43 System
.out
.println("jsShaHex:\t\t\t" + pwdShaHex
);
44 System
.out
.println("pwdShaHex==jsShaHex:\t\t"
45 + (pwdShaHex
.equals(jsShaHex
)));
47 byte[] jsShaArray
= Hex
.decodeHex(jsShaHex
.toCharArray());
48 String jsShaBase64
= new String(Base64
.encodeBase64(jsShaArray
));
49 System
.out
.println("jsShaBase64:\t\t\t" + jsShaBase64
);
50 System
.out
.println("pwdShaBase64==jsShaBase64:\t"
51 + (pwdShaBase64
.equals(jsShaBase64
)));
52 } catch (DecoderException e
) {