1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package javax.crypto.spec; 19 20import java.security.spec.AlgorithmParameterSpec; 21import java.security.spec.MGF1ParameterSpec; 22 23/** 24 * The algorithm parameter specification for the <i>OAEP Padding</i> algorithm. 25 * <p> 26 * This padding algorithm is defined in the <a 27 * href="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1</a> standard. 28 */ 29public class OAEPParameterSpec implements AlgorithmParameterSpec { 30 31 private final String mdName; 32 private final String mgfName; 33 private final AlgorithmParameterSpec mgfSpec; 34 private final PSource pSrc; 35 36 /** 37 * The algorithm parameter instance with default values. 38 * <p> 39 * It uses the following parameters: 40 * <ul><li>message digest : <code>"SHA-1"</code></li> 41 * <li>mask generation function (<i>mgf</i>) : <code>"MGF1"</code></li> 42 * <li>parameters for the <i>mgf</i> : "SHA-1" {@link MGF1ParameterSpec#SHA1}</li> 43 * <li>the source of the label <code>L</code>: {@link PSource.PSpecified#DEFAULT}</li> 44 * </ul> 45 */ 46 public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec(); 47 48 private OAEPParameterSpec() { 49 this.mdName = "SHA-1"; 50 this.mgfName = "MGF1"; 51 this.mgfSpec = MGF1ParameterSpec.SHA1; 52 this.pSrc = PSource.PSpecified.DEFAULT; 53 } 54 55 /** 56 * Creates a new <code>OAEPParameterSpec</code> instance with the specified 57 * <i>message digest</i> algorithm name, <i>mask generation function</i> 58 * (<i>mgf</i>) algorithm name, <i>parameters</i> for the <i>mgf</i> 59 * algorithm and the <i>source of the label <code>L</code></i>. 60 * 61 * @param mdName 62 * the message digest algorithm name. 63 * @param mgfName 64 * the mask generation function algorithm name. 65 * @param mgfSpec 66 * the algorithm parameter specification for the mask generation 67 * function algorithm. 68 * @param pSrc 69 * the source of the label <code>L</code>. 70 * @throws NullPointerException 71 * if one of <code>mdName</code>, <code>mgfName</code> or 72 * <code>pSrc</code> is null. 73 */ 74 public OAEPParameterSpec(String mdName, String mgfName, 75 AlgorithmParameterSpec mgfSpec, PSource pSrc) { 76 if (mdName == null) { 77 throw new NullPointerException("mdName == null"); 78 } else if (mgfName == null) { 79 throw new NullPointerException("mgfName == null"); 80 } else if (pSrc == null) { 81 throw new NullPointerException("pSrc == null"); 82 } 83 this.mdName = mdName; 84 this.mgfName = mgfName; 85 this.mgfSpec = mgfSpec; 86 this.pSrc = pSrc; 87 } 88 89 /** 90 * Returns the algorithm name of the <i>message digest</i>. 91 * 92 * @return the algorithm name of the message digest. 93 */ 94 public String getDigestAlgorithm() { 95 return mdName; 96 } 97 98 /** 99 * Returns the algorithm name of the <i>mask generation function</i>. 100 * 101 * @return the algorithm name of the mask generation function. 102 */ 103 public String getMGFAlgorithm() { 104 return mgfName; 105 } 106 107 /** 108 * Returns the algorithm parameter specification for the mask generation 109 * function algorithm. 110 * 111 * @return the algorithm parameter specification for the mask generation 112 * function algorithm. 113 */ 114 public AlgorithmParameterSpec getMGFParameters() { 115 return mgfSpec; 116 } 117 118 /** 119 * Returns the source of the label <code>L</code>. 120 * 121 * @return the source of the label <code>L</code>. 122 */ 123 public PSource getPSource() { 124 return pSrc; 125 } 126} 127 128