01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * See the License for the specific language governing rights and
10: * limitations under the License.
11: *
12: * The Initial Developer of the Original Code is Simulacra Media Ltd.
13: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14: *
15: * All Rights Reserved.
16: *
17: * Contributor(s):
18: *
19: * Created: 14-Dec-2004 by jejking
20: * Version: $Revision: 1.3 $
21: * Last Updated: $Date: 2005/01/07 16:53:35 $
22: */
23: package org.openharmonise.rm.security.authentication;
24:
25: import org.apache.commons.math.random.*;
26:
27: /**
28: * @author John King
29: *
30: */
31: public class PasswordCryptUtil {
32:
33: private static RandomData random;
34:
35: /**
36: * @param i
37: * @return
38: */
39: public static String getNewSalt(int i) {
40: if (random == null) {
41: random = new RandomDataImpl();
42: }
43: return random.nextSecureHexString(i);
44: }
45:
46: public static void main(String[] args) {
47: // get some basic defaults out for super user
48: try {
49: String super Salt = PasswordCryptUtil.getNewSalt(32);
50: System.out.println("MD 5 - super salt: " + super Salt);
51: PasswordHelper passwordHelper = new CryptPasswordHelper(
52: "MD5");
53: String super Password = passwordHelper.getNewPassword(
54: "Tanger1ne", super Salt);
55: System.out.println("MD 5 - super hashed password: "
56: + super Password);
57:
58: super Salt = PasswordCryptUtil.getNewSalt(40);
59: System.out.println("SHA-1 - super salt: " + super Salt);
60: passwordHelper = new CryptPasswordHelper("SHA-1");
61: super Password = passwordHelper.getNewPassword("Tanger1ne",
62: super Salt);
63: System.out.println("SHA-1 - super hashed password: "
64: + super Password);
65: } catch (RuntimeException e) {
66: // TODO Auto-generated catch block
67: e.printStackTrace();
68: }
69: }
70:
71: }
|