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 javax.crypto;
27
28 import java.security.AlgorithmParameters;
29 import java.security.Provider;
30 import java.security.Key;
31 import java.security.Security;
32 import java.security.NoSuchAlgorithmException;
33 import java.security.NoSuchProviderException;
34 import java.security.InvalidKeyException;
35 import java.security.InvalidAlgorithmParameterException;
36 import java.security.spec.AlgorithmParameterSpec;
37
38 import sun.security.jca.GetInstance.Instance;
39
40 /**
41 * This class provides the functionality of an exemption mechanism, examples
42 * of which are <i>key recovery</i>, <i>key weakening</i>, and
43 * <i>key escrow</i>.
44 *
45 * <p>Applications or applets that use an exemption mechanism may be granted
46 * stronger encryption capabilities than those which don't.
47 *
48 * @since 1.4
49 */
50
51 public class ExemptionMechanism {
52
53 // The provider
54 private Provider provider;
55
56 // The provider implementation (delegate)
111 *
112 * <p> Note that the list of registered providers may be retrieved via
113 * the {@link Security#getProviders() Security.getProviders()} method.
114 *
115 * @implNote
116 * The JDK Reference Implementation additionally uses the
117 * {@code jdk.security.provider.preferred}
118 * {@link Security#getProperty(String) Security} property to determine
119 * the preferred provider order for the specified algorithm. This
120 * may be different than the order of providers returned by
121 * {@link Security#getProviders() Security.getProviders()}.
122 *
123 * @param algorithm the standard name of the requested exemption
124 * mechanism.
125 * See the ExemptionMechanism section in the
126 * <a href=
127 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
128 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
129 * for information about standard exemption mechanism names.
130 *
131 * @return the new <code>ExemptionMechanism</code> object.
132 *
133 * @exception NullPointerException if <code>algorithm</code>
134 * is null.
135 *
136 * @exception NoSuchAlgorithmException if no Provider supports an
137 * ExemptionMechanismSpi implementation for the
138 * specified algorithm.
139 *
140 * @see java.security.Provider
141 */
142 public static final ExemptionMechanism getInstance(String algorithm)
143 throws NoSuchAlgorithmException {
144 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
145 ExemptionMechanismSpi.class, algorithm);
146 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
147 instance.provider, algorithm);
148 }
149
150
151 /**
152 * Returns an <code>ExemptionMechanism</code> object that implements the
153 * specified exemption mechanism algorithm.
154 *
155 * <p> A new ExemptionMechanism object encapsulating the
156 * ExemptionMechanismSpi implementation from the specified provider
157 * is returned. The specified provider must be registered
158 * in the security provider list.
159 *
160 * <p> Note that the list of registered providers may be retrieved via
161 * the {@link Security#getProviders() Security.getProviders()} method.
162
163 * @param algorithm the standard name of the requested exemption mechanism.
164 * See the ExemptionMechanism section in the
165 * <a href=
166 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
167 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
168 * for information about standard exemption mechanism names.
169 *
170 * @param provider the name of the provider.
171 *
172 * @return the new <code>ExemptionMechanism</code> object.
173 *
174 * @exception NullPointerException if <code>algorithm</code>
175 * is null.
176 *
177 * @exception NoSuchAlgorithmException if an ExemptionMechanismSpi
178 * implementation for the specified algorithm is not
179 * available from the specified provider.
180 *
181 * @exception NoSuchProviderException if the specified provider is not
182 * registered in the security provider list.
183 *
184 * @exception IllegalArgumentException if the <code>provider</code>
185 * is null or empty.
186 *
187 * @see java.security.Provider
188 */
189 public static final ExemptionMechanism getInstance(String algorithm,
190 String provider) throws NoSuchAlgorithmException,
191 NoSuchProviderException {
192 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
193 ExemptionMechanismSpi.class, algorithm, provider);
194 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
195 instance.provider, algorithm);
196 }
197
198 /**
199 * Returns an <code>ExemptionMechanism</code> object that implements the
200 * specified exemption mechanism algorithm.
201 *
202 * <p> A new ExemptionMechanism object encapsulating the
203 * ExemptionMechanismSpi implementation from the specified Provider
204 * object is returned. Note that the specified Provider object
205 * does not have to be registered in the provider list.
206 *
207 * @param algorithm the standard name of the requested exemption mechanism.
208 * See the ExemptionMechanism section in the
209 * <a href=
210 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
211 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
212 * for information about standard exemption mechanism names.
213 *
214 * @param provider the provider.
215 *
216 * @return the new <code>ExemptionMechanism</code> object.
217 *
218 * @exception NullPointerException if <code>algorithm</code>
219 * is null.
220 *
221 * @exception NoSuchAlgorithmException if an ExemptionMechanismSpi
222 * implementation for the specified algorithm is not available
223 * from the specified Provider object.
224 *
225 * @exception IllegalArgumentException if the <code>provider</code>
226 * is null.
227 *
228 * @see java.security.Provider
229 */
230 public static final ExemptionMechanism getInstance(String algorithm,
231 Provider provider) throws NoSuchAlgorithmException {
232 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
233 ExemptionMechanismSpi.class, algorithm, provider);
234 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
235 instance.provider, algorithm);
236 }
237
238 /**
239 * Returns the provider of this <code>ExemptionMechanism</code> object.
240 *
241 * @return the provider of this <code>ExemptionMechanism</code> object.
242 */
243 public final Provider getProvider() {
244 return this.provider;
245 }
246
247 /**
248 * Returns whether the result blob has been generated successfully by this
249 * exemption mechanism.
250 *
251 * <p>The method also makes sure that the key passed in is the same as
|
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 javax.crypto;
27
28 import java.security.AlgorithmParameters;
29 import java.security.Provider;
30 import java.security.Key;
31 import java.security.Security;
32 import java.security.NoSuchAlgorithmException;
33 import java.security.NoSuchProviderException;
34 import java.security.InvalidKeyException;
35 import java.security.InvalidAlgorithmParameterException;
36 import java.security.spec.AlgorithmParameterSpec;
37 import java.util.Objects;
38
39 import sun.security.jca.GetInstance.Instance;
40
41 /**
42 * This class provides the functionality of an exemption mechanism, examples
43 * of which are <i>key recovery</i>, <i>key weakening</i>, and
44 * <i>key escrow</i>.
45 *
46 * <p>Applications or applets that use an exemption mechanism may be granted
47 * stronger encryption capabilities than those which don't.
48 *
49 * @since 1.4
50 */
51
52 public class ExemptionMechanism {
53
54 // The provider
55 private Provider provider;
56
57 // The provider implementation (delegate)
112 *
113 * <p> Note that the list of registered providers may be retrieved via
114 * the {@link Security#getProviders() Security.getProviders()} method.
115 *
116 * @implNote
117 * The JDK Reference Implementation additionally uses the
118 * {@code jdk.security.provider.preferred}
119 * {@link Security#getProperty(String) Security} property to determine
120 * the preferred provider order for the specified algorithm. This
121 * may be different than the order of providers returned by
122 * {@link Security#getProviders() Security.getProviders()}.
123 *
124 * @param algorithm the standard name of the requested exemption
125 * mechanism.
126 * See the ExemptionMechanism section in the
127 * <a href=
128 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
129 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
130 * for information about standard exemption mechanism names.
131 *
132 * @return the new {@code ExemptionMechanism} object
133 *
134 * @throws NoSuchAlgorithmException if no {@code Provider} supports an
135 * {@code ExemptionMechanismSpi} implementation for the
136 * specified algorithm
137 *
138 * @throws NullPointerException if {@code algorithm} is {@code null}
139 *
140 * @see java.security.Provider
141 */
142 public static final ExemptionMechanism getInstance(String algorithm)
143 throws NoSuchAlgorithmException {
144 Objects.requireNonNull(algorithm, "null algorithm name");
145 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
146 ExemptionMechanismSpi.class, algorithm);
147 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
148 instance.provider, algorithm);
149 }
150
151
152 /**
153 * Returns an <code>ExemptionMechanism</code> object that implements the
154 * specified exemption mechanism algorithm.
155 *
156 * <p> A new ExemptionMechanism object encapsulating the
157 * ExemptionMechanismSpi implementation from the specified provider
158 * is returned. The specified provider must be registered
159 * in the security provider list.
160 *
161 * <p> Note that the list of registered providers may be retrieved via
162 * the {@link Security#getProviders() Security.getProviders()} method.
163
164 * @param algorithm the standard name of the requested exemption mechanism.
165 * See the ExemptionMechanism section in the
166 * <a href=
167 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
168 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
169 * for information about standard exemption mechanism names.
170 *
171 * @param provider the name of the provider.
172 *
173 * @return the new {@code ExemptionMechanism} object
174 *
175 * @throws IllegalArgumentException if the {@code provider}
176 * is {@code null} or empty
177 *
178 * @throws NoSuchAlgorithmException if an {@code ExemptionMechanismSpi}
179 * implementation for the specified algorithm is not
180 * available from the specified provider
181 *
182 * @throws NoSuchProviderException if the specified provider is not
183 * registered in the security provider list
184 *
185 * @throws NullPointerException if {@code algorithm} is {@code null}
186 *
187 * @see java.security.Provider
188 */
189 public static final ExemptionMechanism getInstance(String algorithm,
190 String provider) throws NoSuchAlgorithmException,
191 NoSuchProviderException {
192 Objects.requireNonNull(algorithm, "null algorithm name");
193 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
194 ExemptionMechanismSpi.class, algorithm, provider);
195 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
196 instance.provider, algorithm);
197 }
198
199 /**
200 * Returns an <code>ExemptionMechanism</code> object that implements the
201 * specified exemption mechanism algorithm.
202 *
203 * <p> A new ExemptionMechanism object encapsulating the
204 * ExemptionMechanismSpi implementation from the specified Provider
205 * object is returned. Note that the specified Provider object
206 * does not have to be registered in the provider list.
207 *
208 * @param algorithm the standard name of the requested exemption mechanism.
209 * See the ExemptionMechanism section in the
210 * <a href=
211 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Exemption">
212 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
213 * for information about standard exemption mechanism names.
214 *
215 * @param provider the provider.
216 *
217 * @return the new {@code ExemptionMechanism} object
218 *
219 * @throws IllegalArgumentException if the {@code provider}
220 * is null
221 *
222 * @throws NoSuchAlgorithmException if an {@code ExemptionMechanismSpi}
223 * implementation for the specified algorithm is not available
224 * from the specified {@code Provider object}
225 *
226 * @exception NullPointerException if {@code algorithm} is {@code null}
227 *
228 * @see java.security.Provider
229 */
230 public static final ExemptionMechanism getInstance(String algorithm,
231 Provider provider) throws NoSuchAlgorithmException {
232 Objects.requireNonNull(algorithm, "null algorithm name");
233 Instance instance = JceSecurity.getInstance("ExemptionMechanism",
234 ExemptionMechanismSpi.class, algorithm, provider);
235 return new ExemptionMechanism((ExemptionMechanismSpi)instance.impl,
236 instance.provider, algorithm);
237 }
238
239 /**
240 * Returns the provider of this <code>ExemptionMechanism</code> object.
241 *
242 * @return the provider of this <code>ExemptionMechanism</code> object.
243 */
244 public final Provider getProvider() {
245 return this.provider;
246 }
247
248 /**
249 * Returns whether the result blob has been generated successfully by this
250 * exemption mechanism.
251 *
252 * <p>The method also makes sure that the key passed in is the same as
|