Search in sources :

Example 21 with DSAParameterSpec

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

the class AbstractP11Slot method generateDSAKeypair.

@Override
public P11ObjectIdentifier generateDSAKeypair(int plength, int qlength, String label, P11NewKeyControl control) throws P11TokenException {
    ParamUtil.requireMin("plength", plength, 1024);
    if (plength % 1024 != 0) {
        throw new IllegalArgumentException("key size is not multiple of 1024: " + plength);
    }
    assertWritable("generateDSAKeypair");
    assertMechanismSupported(PKCS11Constants.CKM_DSA_KEY_PAIR_GEN);
    if (getObjectIdForLabel(label) != null) {
        throw new P11DuplicateEntityException("identity with label " + label + " already exists");
    }
    DSAParameterSpec dsaParams = DSAParameterCache.getDSAParameterSpec(plength, qlength, random);
    P11Identity identity = generateDSAKeypair0(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG(), label, control);
    addIdentity(identity);
    P11ObjectIdentifier objId = identity.getIdentityId().getObjectId();
    LOG.info("generated DSA keypair {}", objId);
    return objId;
}
Also used : P11DuplicateEntityException(org.xipki.security.exception.P11DuplicateEntityException) DSAParameterSpec(java.security.spec.DSAParameterSpec)

Example 22 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project Bytecoder by mirkosertic.

the class DSAParameterGenerator method engineGenerateParameters.

/**
 * Generates the parameters.
 *
 * @return the new AlgorithmParameters object
 */
@Override
protected AlgorithmParameters engineGenerateParameters() {
    AlgorithmParameters algParams = null;
    try {
        if (this.random == null) {
            this.random = new SecureRandom();
        }
        if (valueL == -1) {
            try {
                engineInit(DEFAULTS, this.random);
            } catch (InvalidAlgorithmParameterException iape) {
            // should never happen
            }
        }
        BigInteger[] pAndQ = generatePandQ(this.random, valueL, valueN, seedLen);
        BigInteger paramP = pAndQ[0];
        BigInteger paramQ = pAndQ[1];
        BigInteger paramG = generateG(paramP, paramQ);
        DSAParameterSpec dsaParamSpec = new DSAParameterSpec(paramP, paramQ, paramG);
        algParams = AlgorithmParameters.getInstance("DSA", "SUN");
        algParams.init(dsaParamSpec);
    } catch (InvalidParameterSpecException e) {
        // this should never happen
        throw new RuntimeException(e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        // this should never happen, because we provide it
        throw new RuntimeException(e.getMessage());
    } catch (NoSuchProviderException e) {
        // this should never happen, because we provide it
        throw new RuntimeException(e.getMessage());
    }
    return algParams;
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 23 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project j2objc by google.

the class DSAParamsTest method test_getG.

/**
 * java.security.interfaces.DSAParams
 * #getG()
 */
public void test_getG() {
    DSAParams params = new DSAParameterSpec(p, q, g);
    assertEquals("Invalid G", g, params.getG());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams)

Example 24 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project j2objc by google.

the class DSAParamsTest method test_getQ.

/**
 * java.security.interfaces.DSAParams
 * #getQ()
 */
public void test_getQ() {
    DSAParams params = new DSAParameterSpec(p, q, g);
    assertEquals("Invalid Q", q, params.getQ());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams)

Example 25 with DSAParameterSpec

use of java.security.spec.DSAParameterSpec in project j2objc by google.

the class DSAParameterSpecTest method testDSAParameterSpec.

/**
 * Ctor test
 */
public final void testDSAParameterSpec() {
    AlgorithmParameterSpec aps = new DSAParameterSpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"));
    assertTrue(aps instanceof DSAParameterSpec);
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) BigInteger(java.math.BigInteger) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

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