java.security.spec.InvalidParameterSpecException Java Examples

The following examples show how to use java.security.spec.InvalidParameterSpecException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChaCha20Poly1305Parameters.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the ChaCha20Poly1305Parameters using an IvParameterSpec.
 *
 * @param paramSpec the {@code IvParameterSpec} used to configure
 *      this object.
 *
 * @throws InvalidParameterSpecException if an object of a type other
 *      than {@code IvParameterSpec} is used.
 */
@Override
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof IvParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    IvParameterSpec ivps = (IvParameterSpec)paramSpec;

    // Obtain the nonce
    nonce = ivps.getIV();
    if (nonce.length != 12) {
        throw new InvalidParameterSpecException("ChaCha20-Poly1305 nonce" +
                " must be 12 bytes in length");
    }
}
 
Example #2
Source File: RC2Parameters.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #3
Source File: cryptoCommon.java    From fido2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 *
 * @param publickeybytes
 * @return
 * @throws java.security.spec.InvalidKeySpecException
 * @throws java.security.NoSuchAlgorithmException
 * @throws java.security.NoSuchProviderException
 * @throws java.security.spec.InvalidParameterSpecException
 */
public static ECPublicKey getUserECPublicKey(byte[] publickeybytes) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException, InvalidParameterSpecException {

    //append the sign byte to the arrays
    byte[] processedXData = new byte[EC_POINTSIZE];
    byte[] processedYData = new byte[EC_POINTSIZE];
    System.arraycopy(publickeybytes, 1, processedXData, 0, EC_POINTSIZE);
    System.arraycopy(publickeybytes, EC_POINTSIZE + 1, processedYData, 0, EC_POINTSIZE);

    ECPoint pubPoint = new ECPoint(new BigInteger(1, processedXData), new BigInteger(1, processedYData));
    AlgorithmParameters params = AlgorithmParameters.getInstance("EC", BC_FIPS_PROVIDER);
    params.init(new ECGenParameterSpec("prime256v1"));
    ECParameterSpec ecParameters = params.getParameterSpec(ECParameterSpec.class);
    ECPublicKeySpec pubECSpec = new ECPublicKeySpec(pubPoint, ecParameters);
    return (ECPublicKey) KeyFactory.getInstance("EC", BC_FIPS_PROVIDER).generatePublic(pubECSpec);
}
 
Example #4
Source File: DSAPrivateKey.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #5
Source File: DSAParameters.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #6
Source File: DSAPrivateKey.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #7
Source File: SupportedGroupsExtension.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
static ECGenParameterSpec getECGenParamSpec(NamedGroup namedGroup) {
    if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) {
        throw new RuntimeException(
                "Not a named EC group: " + namedGroup);
    }

    AlgorithmParameters params = namedGroupParams.get(namedGroup);
    if (params == null) {
        throw new RuntimeException(
                "Not a supported EC named group: " + namedGroup);
    }

    try {
        return params.getParameterSpec(ECGenParameterSpec.class);
    } catch (InvalidParameterSpecException ipse) {
        // should be unlikely
        return new ECGenParameterSpec(namedGroup.oid);
    }
}
 
Example #8
Source File: TestDSAGenParameterSpec.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testDSAGenParameterSpec(DataTuple dataTuple)
        throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n",
            dataTuple.primePLen, dataTuple.subprimeQLen);

    AlgorithmParameterGenerator apg
            = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME,
                    PROVIDER_NAME);

    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }

    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();

        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        throw new RuntimeException("Test case failed.", ipe);
    }
}
 
Example #9
Source File: Cipher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key,
        AlgorithmParameters params)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Convert the specified parameters into specs and then delegate.
    AlgorithmParameterSpec pSpec;
    try {
        pSpec = getAlgorithmParameterSpec(params);
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidAlgorithmParameterException
            ("Failed to retrieve algorithm parameter specification");
    }
    checkCryptoPerm(checkSpi, key, pSpec);
}
 
Example #10
Source File: DSAPublicKey.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #11
Source File: DSAParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #12
Source File: Cipher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key)
        throws InvalidKeyException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Check if key size and default parameters are within legal limits
    AlgorithmParameterSpec params;
    try {
        params = getAlgorithmParameterSpec(checkSpi.engineGetParameters());
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidKeyException
            ("Unsupported default algorithm parameters");
    }
    if (!passCryptoPermCheck(checkSpi, key, params)) {
        throw new InvalidKeyException(
            "Illegal key size or default parameters");
    }
}
 
Example #13
Source File: RC2Parameters.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #14
Source File: RSACipher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected AlgorithmParameters engineGetParameters() {
    if (spec != null && spec instanceof OAEPParameterSpec) {
        try {
            AlgorithmParameters params =
                AlgorithmParameters.getInstance("OAEP",
                    SunJCE.getInstance());
            params.init(spec);
            return params;
        } catch (NoSuchAlgorithmException nsae) {
            // should never happen
            throw new RuntimeException("Cannot find OAEP " +
                " AlgorithmParameters implementation in SunJCE provider");
        } catch (InvalidParameterSpecException ipse) {
            // should never happen
            throw new RuntimeException("OAEPParameterSpec not supported");
        }
    } else {
        return null;
    }
}
 
Example #15
Source File: RSACipher.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params == null) {
        init(opmode, key, random, null);
    } else {
        try {
            OAEPParameterSpec spec =
                    params.getParameterSpec(OAEPParameterSpec.class);
            init(opmode, key, random, spec);
        } catch (InvalidParameterSpecException ipse) {
            InvalidAlgorithmParameterException iape =
                new InvalidAlgorithmParameterException("Wrong parameter");
            iape.initCause(ipse);
            throw iape;
        }
    }
}
 
Example #16
Source File: RSACipher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params == null) {
        init(opmode, key, random, null);
    } else {
        try {
            OAEPParameterSpec spec =
                    params.getParameterSpec(OAEPParameterSpec.class);
            init(opmode, key, random, spec);
        } catch (InvalidParameterSpecException ipse) {
            InvalidAlgorithmParameterException iape =
                new InvalidAlgorithmParameterException("Wrong parameter");
            iape.initCause(ipse);
            throw iape;
        }
    }
}
 
Example #17
Source File: Cipher.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key,
        AlgorithmParameters params)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Convert the specified parameters into specs and then delegate.
    AlgorithmParameterSpec pSpec;
    try {
        pSpec = getAlgorithmParameterSpec(params);
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidAlgorithmParameterException
            ("Failed to retrieve algorithm parameter specification");
    }
    checkCryptoPerm(checkSpi, key, pSpec);
}
 
Example #18
Source File: Cipher.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private AlgorithmParameterSpec getAlgorithmParameterSpec(
                                  AlgorithmParameters params)
        throws InvalidParameterSpecException {
    if (params == null) {
        return null;
    }

    String alg = params.getAlgorithm().toUpperCase(Locale.ENGLISH);

    if (alg.equalsIgnoreCase("RC2")) {
        return params.getParameterSpec(RC2ParameterSpec.class);
    }

    if (alg.equalsIgnoreCase("RC5")) {
        return params.getParameterSpec(RC5ParameterSpec.class);
    }

    if (alg.startsWith("PBE")) {
        return params.getParameterSpec(PBEParameterSpec.class);
    }

    if (alg.startsWith("DES")) {
        return params.getParameterSpec(IvParameterSpec.class);
    }
    return null;
}
 
Example #19
Source File: TestDSAGenParameterSpec.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testDSAGenParameterSpec(DataTuple dataTuple)
        throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n",
            dataTuple.primePLen, dataTuple.subprimeQLen);

    AlgorithmParameterGenerator apg
            = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME,
                    PROVIDER_NAME);

    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }

    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();

        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        throw new RuntimeException("Test case failed.", ipe);
    }
}
 
Example #20
Source File: GCMParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
        T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {

    if (GCMParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(new GCMParameterSpec(tLen * 8, iv));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example #21
Source File: FIDO2RegistrationBean.java    From fido2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
private FIDO2AttestationObject retrieveAttestationObjectFromFIDOResponseObject(JsonObject response){
    try {
        String attestationObjectString = response.getString(skfsConstants.JSON_KEY_ATTESTATIONOBJECT);
        FIDO2AttestationObject attObject = new FIDO2AttestationObject();
        attObject.decodeAttestationObject(attestationObjectString);
        return attObject;
    } catch (IOException | NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException | InvalidParameterSpecException ex) {
        skfsLogger.log(skfsConstants.SKFE_LOGGER,Level.FINE, "FIDO-ERR-5011", "Invalid attestaionObject: " + ex);
        throw new SKIllegalArgumentException("Invalid attestaionObject");
    }
}
 
Example #22
Source File: BlockCipherParamsCore.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void init(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {
    if (!(paramSpec instanceof IvParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    byte[] tmpIv = ((IvParameterSpec)paramSpec).getIV();
    if (tmpIv.length != block_size) {
        throw new InvalidParameterSpecException("IV not " +
                    block_size + " bytes long");
    }
    iv = tmpIv.clone();
}
 
Example #23
Source File: PBES2Parameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
        T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
    if (PBEParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new PBEParameterSpec(this.salt, this.iCount, this.cipherParam));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example #24
Source File: PBES2Parameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
   if (!(paramSpec instanceof PBEParameterSpec)) {
       throw new InvalidParameterSpecException
           ("Inappropriate parameter specification");
   }
   this.salt = ((PBEParameterSpec)paramSpec).getSalt().clone();
   this.iCount = ((PBEParameterSpec)paramSpec).getIterationCount();
   this.cipherParam = ((PBEParameterSpec)paramSpec).getParameterSpec();
}
 
Example #25
Source File: cryptoCommon.java    From fido2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ECPublicKey getUserECPublicKey(byte[] x, byte[] y, String curveString) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException, InvalidParameterSpecException {

        //append the sign byte to the arrays
        ECPoint pubPoint = new ECPoint(new BigInteger(1, x), new BigInteger(1, y));
        AlgorithmParameters params = AlgorithmParameters.getInstance("EC", BC_FIPS_PROVIDER);
        params.init(new ECGenParameterSpec(curveString));
        ECParameterSpec ecParameters = params.getParameterSpec(ECParameterSpec.class);
        ECPublicKeySpec pubECSpec = new ECPublicKeySpec(pubPoint, ecParameters);
        return (ECPublicKey) KeyFactory.getInstance("EC", BC_FIPS_PROVIDER).generatePublic(pubECSpec);
    }
 
Example #26
Source File: AESParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (AlgorithmParameterSpec.class.isAssignableFrom(paramSpec)) {
        return core.getParameterSpec(paramSpec);
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter Specification");
    }
}
 
Example #27
Source File: AESParameters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (AlgorithmParameterSpec.class.isAssignableFrom(paramSpec)) {
        return core.getParameterSpec(paramSpec);
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter Specification");
    }
}
 
Example #28
Source File: DESParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (AlgorithmParameterSpec.class.isAssignableFrom(paramSpec)) {
        return core.getParameterSpec(paramSpec);
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter Specification");
    }
}
 
Example #29
Source File: TestDSAGenParameterSpec.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkParam(AlgorithmParameters param,
        DSAGenParameterSpec genParam) throws InvalidParameterSpecException,
        NoSuchAlgorithmException, NoSuchProviderException,
        InvalidAlgorithmParameterException {
    String algorithm = param.getAlgorithm();
    if (!algorithm.equalsIgnoreCase(ALGORITHM_NAME)) {
        throw new RuntimeException(
                "Unexpected type of parameters: " + algorithm);
    }

    DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
    int valueL = spec.getP().bitLength();
    int strengthP = genParam.getPrimePLength();
    if (strengthP != valueL) {
        System.out.printf("P: Expected %d but actual %d%n", strengthP,
                valueL);
        throw new RuntimeException("Wrong P strength");
    }

    int valueN = spec.getQ().bitLength();
    int strengthQ = genParam.getSubprimeQLength();
    if (strengthQ != valueN) {
        System.out.printf("Q: Expected %d but actual %d%n", strengthQ,
                valueN);
        throw new RuntimeException("Wrong Q strength");
    }

    if (genParam.getSubprimeQLength() != genParam.getSeedLength()) {
        System.out.println("Defaut seed length should be the same as Q.");
        throw new RuntimeException("Wrong seed length");
    }

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
            PROVIDER_NAME);
    keyGen.initialize(spec);
}
 
Example #30
Source File: OAEPParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
                                  new PSource.PSpecified(p)));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}