2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.baseservice.encrypt.cbb;
18 import org.openo.baseservice.encrypt.cbb.impl.AesCipherFactory;
19 import org.openo.baseservice.encrypt.cbb.inf.AbstractCipher;
20 import org.openo.baseservice.encrypt.cbb.inf.AbstractCipherFactory;
23 * Helps create cipher instances from factory.<br/>
25 * Creates the cipher instances using cipher factory. By default it uses AesCipherFactory.
26 * Can be changed through spring.
30 * @version 08-Jun-2016
32 public final class CipherCreator {
34 private static CipherCreator instance = new CipherCreator();
36 private AbstractCipherFactory factory = new AesCipherFactory();
46 private CipherCreator() {
57 public static CipherCreator instance() {
62 * Creates cipher with default key.
65 * @return cipher instance with default key.
68 public AbstractCipher create() {
69 return factory.createCipherManager();
73 * Creates cipher instance with a key.
76 * @param key the key to be used for encryption and decryption.
77 * @return cipher instance with specified key.
80 public AbstractCipher create(final String key) {
81 return factory.createCipherManager(key);
85 * Sets the cipher factory instance.
88 * @param factory cipher factory.
91 public void setFactory(final AbstractCipherFactory factory) {
92 this.factory = factory;