Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AesCipherService |
|
| 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; | |
20 | ||
21 | /** | |
22 | * {@code CipherService} using the {@code AES} cipher algorithm for all encryption, decryption, and key operations. | |
23 | * <p/> | |
24 | * The AES algorithm can support key sizes of {@code 128}, {@code 192} and {@code 256} bits<b>*</b>. This implementation | |
25 | * defaults to 128 bits. | |
26 | * <p/> | |
27 | * Note that this class retains the parent class's default {@link OperationMode#CBC CBC} mode of operation | |
28 | * instead of the typical JDK default of {@link OperationMode#ECB ECB}. {@code ECB} should not be used in | |
29 | * security-sensitive environments because {@code ECB} does not allow for initialization vectors, which are | |
30 | * considered necessary for strong encryption. See the {@link DefaultBlockCipherService parent class}'s JavaDoc and the | |
31 | * {@link JcaCipherService JcaCipherService} JavaDoc for more on why the JDK default should not be used and is not | |
32 | * used in this implementation. | |
33 | * <p/> | |
34 | * <b>*</b> Generating and using AES key sizes greater than 128 require installation of the | |
35 | * <a href="http://java.sun.com/javase/downloads/index.jsp">Java Cryptography Extension (JCE) Unlimited Strength | |
36 | * Jurisdiction Policy files</a>. | |
37 | * | |
38 | * @since 1.0 | |
39 | */ | |
40 | public class AesCipherService extends DefaultBlockCipherService { | |
41 | ||
42 | private static final String ALGORITHM_NAME = "AES"; | |
43 | ||
44 | /** | |
45 | * Creates a new {@link CipherService} instance using the {@code AES} cipher algorithm with the following | |
46 | * important cipher default attributes: | |
47 | * <table> | |
48 | * <tr> | |
49 | * <th>Attribute</th> | |
50 | * <th>Value</th> | |
51 | * </tr> | |
52 | * <tr> | |
53 | * <td>{@link #setKeySize keySize}</td> | |
54 | * <td>{@code 128} bits</td> | |
55 | * </tr> | |
56 | * <tr> | |
57 | * <td>{@link #setBlockSize blockSize}</td> | |
58 | * <td>{@code 128} bits (required for {@code AES}</td> | |
59 | * </tr> | |
60 | * <tr> | |
61 | * <td>{@link #setMode mode}</td> | |
62 | * <td>{@link OperationMode#CBC CBC}<b>*</b></td> | |
63 | * </tr> | |
64 | * <tr> | |
65 | * <td>{@link #setPaddingScheme paddingScheme}</td> | |
66 | * <td>{@link PaddingScheme#PKCS5 PKCS5}</td> | |
67 | * </tr> | |
68 | * <tr> | |
69 | * <td>{@link #setInitializationVectorSize(int) initializationVectorSize}</td> | |
70 | * <td>{@code 128} bits</td> | |
71 | * </tr> | |
72 | * <tr> | |
73 | * <td>{@link #setGenerateInitializationVectors(boolean) generateInitializationVectors}</td> | |
74 | * <td>{@code true}<b>**</b></td> | |
75 | * </tr> | |
76 | * </table> | |
77 | * <p/> | |
78 | * <b>*</b> The {@link OperationMode#CBC CBC} operation mode is used instead of the JDK default {@code ECB} to | |
79 | * ensure strong encryption. {@code ECB} should not be used in security-sensitive environments - see the | |
80 | * {@link DefaultBlockCipherService DefaultBlockCipherService} class JavaDoc's "Operation Mode" section | |
81 | * for more. | |
82 | * <p/> | |
83 | * <b>**</b>In conjunction with the default {@code CBC} operation mode, initialization vectors are generated by | |
84 | * default to ensure strong encryption. See the {@link JcaCipherService JcaCipherService} class JavaDoc for more. | |
85 | */ | |
86 | public AesCipherService() { | |
87 | 4 | super(ALGORITHM_NAME); |
88 | 4 | } |
89 | ||
90 | } |