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;
}
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;
}
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());
}
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());
}
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);
}
Aggregations