1 /* 2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.crypto.provider; 27 28 import java.io.*; 29 import java.security.AlgorithmParametersSpi; 30 import java.security.spec.AlgorithmParameterSpec; 31 import java.security.spec.InvalidParameterSpecException; 32 33 /** 34 * This class implements the parameter (IV) used with the AES algorithm 35 * in feedback-mode. IV is defined in the standards as follows: 36 * 37 * <pre> 38 * IV ::= OCTET STRING -- 16 octets 39 * </pre> 40 * 41 * @author Valerie Peng 42 * 43 */ 44 public final class AESParameters extends AlgorithmParametersSpi { 45 46 private BlockCipherParamsCore core; 47 AESParameters()48 public AESParameters() { 49 core = new BlockCipherParamsCore(AESConstants.AES_BLOCK_SIZE); 50 } 51 engineInit(AlgorithmParameterSpec paramSpec)52 protected void engineInit(AlgorithmParameterSpec paramSpec) 53 throws InvalidParameterSpecException { 54 core.init(paramSpec); 55 } 56 engineInit(byte[] encoded)57 protected void engineInit(byte[] encoded) 58 throws IOException { 59 core.init(encoded); 60 } 61 engineInit(byte[] encoded, String decodingMethod)62 protected void engineInit(byte[] encoded, String decodingMethod) 63 throws IOException { 64 core.init(encoded, decodingMethod); 65 } 66 67 protected <T extends AlgorithmParameterSpec> engineGetParameterSpec(Class<T> paramSpec)68 T engineGetParameterSpec(Class<T> paramSpec) 69 throws InvalidParameterSpecException { 70 if (AlgorithmParameterSpec.class.isAssignableFrom(paramSpec)) { 71 return core.getParameterSpec(paramSpec); 72 } else { 73 throw new InvalidParameterSpecException 74 ("Inappropriate parameter Specification"); 75 } 76 } 77 engineGetEncoded()78 protected byte[] engineGetEncoded() throws IOException { 79 return core.getEncoded(); 80 } 81 engineGetEncoded(String encodingMethod)82 protected byte[] engineGetEncoded(String encodingMethod) 83 throws IOException { 84 return core.getEncoded(); 85 } 86 engineToString()87 protected String engineToString() { 88 return core.toString(); 89 } 90 } 91