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