Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Sha1Hash |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.shiro.crypto.hash; | |
20 | ||
21 | import org.apache.shiro.codec.Base64; | |
22 | import org.apache.shiro.codec.Hex; | |
23 | ||
24 | ||
25 | /** | |
26 | * Generates an SHA-1 Hash (Secure Hash Standard, NIST FIPS 180-1) from a given input <tt>source</tt> with an | |
27 | * optional <tt>salt</tt> and hash iterations. | |
28 | * <p/> | |
29 | * See the {@link SimpleHash SimpleHash} parent class JavaDoc for a detailed explanation of Hashing | |
30 | * techniques and how the overloaded constructors function. | |
31 | * | |
32 | * @since 0.9 | |
33 | */ | |
34 | public class Sha1Hash extends SimpleHash { | |
35 | ||
36 | //TODO - complete JavaDoc | |
37 | ||
38 | public static final String ALGORITHM_NAME = "SHA-1"; | |
39 | ||
40 | public Sha1Hash() { | |
41 | 0 | super(ALGORITHM_NAME); |
42 | 0 | } |
43 | ||
44 | public Sha1Hash(Object source) { | |
45 | 7 | super(ALGORITHM_NAME, source); |
46 | 7 | } |
47 | ||
48 | public Sha1Hash(Object source, Object salt) { | |
49 | 2 | super(ALGORITHM_NAME, source, salt); |
50 | 2 | } |
51 | ||
52 | public Sha1Hash(Object source, Object salt, int hashIterations) { | |
53 | 0 | super(ALGORITHM_NAME, source, salt, hashIterations); |
54 | 0 | } |
55 | ||
56 | public static Sha1Hash fromHexString(String hex) { | |
57 | 0 | Sha1Hash hash = new Sha1Hash(); |
58 | 0 | hash.setBytes(Hex.decode(hex)); |
59 | 0 | return hash; |
60 | } | |
61 | ||
62 | public static Sha1Hash fromBase64String(String base64) { | |
63 | 0 | Sha1Hash hash = new Sha1Hash(); |
64 | 0 | hash.setBytes(Base64.decode(base64)); |
65 | 0 | return hash; |
66 | } | |
67 | } |