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 module hunt.shiro.crypto.AbstractSymmetricCipherService; 20 21 import hunt.shiro.crypto.JcaCipherService; 22 23 // import javax.crypto.KeyGenerator; 24 import hunt.security.Key; 25 // import java.security.NoSuchAlgorithmException; 26 import hunt.Exceptions; 27 28 /** 29 * Base abstract class for supporting symmetric key cipher algorithms. 30 * 31 * @since 1.0 32 */ 33 abstract class AbstractSymmetricCipherService : JcaCipherService { 34 35 protected this(string algorithmName) { 36 super(algorithmName); 37 } 38 39 /** 40 * Generates a new {@link java.security.Key Key} suitable for this CipherService's {@link #getAlgorithmName() algorithm} 41 * by calling {@link #generateNewKey(int) generateNewKey(128)} (uses a 128 bit size by default). 42 * 43 * @return a new {@link java.security.Key Key}, 128 bits in length. 44 */ 45 Key generateNewKey() { 46 return generateNewKey(getKeySize()); 47 } 48 49 /** 50 * Generates a new {@link Key Key} of the specified size suitable for this CipherService 51 * (based on the {@link #getAlgorithmName() algorithmName} using the JDK {@link javax.crypto.KeyGenerator KeyGenerator}. 52 * 53 * @param keyBitSize the bit size of the key to create 54 * @return the created key suitable for use with this CipherService 55 */ 56 Key generateNewKey(int keyBitSize) { 57 // KeyGenerator kg; 58 // try { 59 // kg = KeyGenerator.getInstance(getAlgorithmName()); 60 // } catch (NoSuchAlgorithmException e) { 61 // string msg = "Unable to acquire " ~ getAlgorithmName() ~ " algorithm. This is required to function."; 62 // throw new IllegalStateException(msg, e); 63 // } 64 // kg.init(keyBitSize); 65 // return kg.generateKey(); 66 implementationMissing(false); 67 return null; 68 } 69 70 }