001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.jose.crypto.impl; 019 020 021import java.security.AlgorithmParameters; 022import java.security.NoSuchAlgorithmException; 023import java.security.Provider; 024 025 026/** 027 * Utility for creating {@link java.security.AlgorithmParameters} objects with 028 * an optional JCA provider. 029 * 030 * @author Justin Richer 031 */ 032public class AlgorithmParametersHelper { 033 034 035 /** 036 * Creates a new {@link java.security.AlgorithmParameters} instance. 037 * 038 * @param name The name of the requested algorithm. Must not be 039 * {@code null}. 040 * @param provider The JCA provider, {@code null} to use the default. 041 * 042 * @return The AlgorithmParameters instance. 043 * 044 * @throws NoSuchAlgorithmException If an AlgorithmParameterGeneratorSpi 045 * implementation for the specified 046 * algorithm is not available from the 047 * specified Provider object. 048 */ 049 public static AlgorithmParameters getInstance(final String name, final Provider provider) 050 throws NoSuchAlgorithmException { 051 052 if (provider == null) { 053 return AlgorithmParameters.getInstance(name); 054 } else { 055 return AlgorithmParameters.getInstance(name, provider); 056 } 057 } 058}