1 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2 *
3 * Licensed under the Apache License, Version 2.0 (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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.acegisecurity.providers.encoding;
16
17 /**
18 * <p>SHA implementation of PasswordEncoder.</p>
19 * <p>If a <code>null</code> password is presented, it will be treated as an empty <code>String</code> ("")
20 * password.</p>
21 * <p>As SHA is a one-way hash, the salt can contain any characters. The default strength for the SHA encoding is SHA-1.
22 * If you wish to use higher strengths use the argumented constructor.
23 * {@link #ShaPasswordEncoder(int strength)}
24 * </p>
25 * <p>
26 * The applicationContext example...
27 * <pre>
28 * <bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.ShaPasswordEncoder">
29 * <constructor-arg value="256"/>
30 * </bean>
31 * </pre>
32 *
33 * @author Ray Krueger
34 * @author colin sampaleanu
35 * @author Ben Alex
36 * @version $Id: ShaPasswordEncoder.java 1784 2007-02-24 21:00:24Z luke_t $
37 */
38 public class ShaPasswordEncoder extends MessageDigestPasswordEncoder {
39
40 /**
41 * Initializes the ShaPasswordEncoder for SHA-1 strength
42 */
43 public ShaPasswordEncoder() {
44 this(1);
45 }
46
47 /**
48 * Initialize the ShaPasswordEncoder with a given SHA stength as supported by the JVM
49 * EX: <code>ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);</code> initializes with SHA-256
50 *
51 * @param strength EX: 1, 256, 384, 512
52 */
53 public ShaPasswordEncoder(int strength) {
54 super("SHA-" + strength);
55 }
56 }