Search in sources :

Example 16 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project jdk8u_jdk by JetBrains.

the class DSAPrivateKey method getParams.

/**
     * 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;
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 17 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project jdk8u_jdk by JetBrains.

the class DSAPublicKey method getParams.

/**
     * 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;
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 18 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project jdk8u_jdk by JetBrains.

the class TestDSAGenParameterSpec method checkParam.

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");
    }
    // use the parameters to generate real DSA keys
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);
    keyGen.initialize(spec);
    keyGen.generateKeyPair();
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator)

Example 19 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project xipki by xipki.

the class KeyUtil method generateDSAKeypair.

// CHECKSTYLE:SKIP
public static KeyPair generateDSAKeypair(DSAParameters dsaParams, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
    DSAParameterSpec dsaParamSpec = new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
    KeyPairGenerator kpGen = getKeyPairGenerator("DSA");
    synchronized (kpGen) {
        kpGen.initialize(dsaParamSpec, random);
        return kpGen.generateKeyPair();
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator)

Example 20 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project xipki by xipki.

the class KeyUtil method generateDSAKeypair.

// CHECKSTYLE:SKIP
public static KeyPair generateDSAKeypair(int plength, int qlength, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
    DSAParameterSpec dsaParamSpec = DSAParameterCache.getDSAParameterSpec(plength, qlength, random);
    KeyPairGenerator kpGen = getKeyPairGenerator("DSA");
    synchronized (kpGen) {
        kpGen.initialize(dsaParamSpec, random);
        return kpGen.generateKeyPair();
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator)

Aggregations

DSAParameterSpec (java.security.spec.DSAParameterSpec)56 BigInteger (java.math.BigInteger)20 DSAParams (java.security.interfaces.DSAParams)16 KeyPairGenerator (java.security.KeyPairGenerator)12 SecureRandom (java.security.SecureRandom)10 AlgorithmParameters (java.security.AlgorithmParameters)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)6 DSAPublicKey (java.security.interfaces.DSAPublicKey)6 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)6 KeyPair (java.security.KeyPair)5 InvalidParameterException (java.security.InvalidParameterException)4 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)3 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)2 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)2