Search in sources :

Example 31 with DSAPublicKey

use of java.security.interfaces.DSAPublicKey in project jdk8u_jdk by JetBrains.

the class BasicChecker method makeInheritedParamsKey.

/**
     * Internal method to create a new key with inherited key parameters.
     *
     * @param keyValueKey key from which to obtain key value
     * @param keyParamsKey key from which to obtain key parameters
     * @return new public key having value and parameters
     * @throws CertPathValidatorException if keys are not appropriate types
     * for this operation
     */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey, PublicKey keyParamsKey) throws CertPathValidatorException {
    if (!(keyValueKey instanceof DSAPublicKey) || !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " + "appropriate type for " + "inheriting parameters");
    DSAParams params = ((DSAPublicKey) keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey) keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y, params.getP(), params.getQ(), params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" + " inherited parameters: " + e.getMessage(), e);
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) GeneralSecurityException(java.security.GeneralSecurityException) BigInteger(java.math.BigInteger) DSAParams(java.security.interfaces.DSAParams) KeyFactory(java.security.KeyFactory) DSAPublicKey(java.security.interfaces.DSAPublicKey) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Aggregations

DSAPublicKey (java.security.interfaces.DSAPublicKey)31 DSAParams (java.security.interfaces.DSAParams)19 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)11 PublicKey (java.security.PublicKey)10 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)10 BigInteger (java.math.BigInteger)9 RSAPublicKey (java.security.interfaces.RSAPublicKey)8 InvalidKeyException (java.security.InvalidKeyException)7 DSAPrivateKeySpec (java.security.spec.DSAPrivateKeySpec)6 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)6 IOException (java.io.IOException)5 GeneralSecurityException (java.security.GeneralSecurityException)5 KeyPairGenerator (java.security.KeyPairGenerator)5 X509Certificate (java.security.cert.X509Certificate)5 KeyFactory (java.security.KeyFactory)4 KeyPair (java.security.KeyPair)4 CertPathValidatorException (java.security.cert.CertPathValidatorException)4 DSAParameterSpec (java.security.spec.DSAParameterSpec)4 CertificateException (java.security.cert.CertificateException)3 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)3