KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > security > authentication > PasswordCryptUtil


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * 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 /**
29  * @author John King
30  *
31  */

32 public class PasswordCryptUtil {
33
34     private static RandomData random;
35     
36     /**
37      * @param i
38      * @return
39      */

40     public static String JavaDoc getNewSalt(int i) {
41         if (random == null) {
42             random = new RandomDataImpl();
43         }
44         return random.nextSecureHexString(i);
45     }
46     
47     public static void main(String JavaDoc[] args) {
48         // get some basic defaults out for super user
49
try {
50             String JavaDoc superSalt = PasswordCryptUtil.getNewSalt(32);
51             System.out.println("MD 5 - super salt: " + superSalt);
52             PasswordHelper passwordHelper = new CryptPasswordHelper("MD5");
53             String JavaDoc superPassword = passwordHelper.getNewPassword("Tanger1ne", superSalt);
54             System.out.println("MD 5 - super hashed password: " + superPassword);
55             
56             superSalt = PasswordCryptUtil.getNewSalt(40);
57             System.out.println("SHA-1 - super salt: " + superSalt);
58             passwordHelper = new CryptPasswordHelper("SHA-1");
59             superPassword = passwordHelper.getNewPassword("Tanger1ne", superSalt);
60             System.out.println("SHA-1 - super hashed password: " + superPassword);
61         }
62         catch (RuntimeException JavaDoc e) {
63             // TODO Auto-generated catch block
64
e.printStackTrace();
65         }
66     }
67
68 }
69
Popular Tags