use of java.security.spec.DSAParameterSpec in project xipki by xipki.
the class CaClientExample method generateDsaKeypair.
protected static MyKeypair generateDsaKeypair() throws Exception {
// plen: 2048, qlen: 256
DSAParameterSpec spec = new DSAParameterSpec(P2048_Q256_P, P2048_Q256_Q, P2048_Q256_G);
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("DSA");
kpGen.initialize(spec);
KeyPair kp = kpGen.generateKeyPair();
DSAPublicKey dsaPubKey = (DSAPublicKey) kp.getPublic();
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new ASN1Integer(dsaPubKey.getParams().getP()));
vec.add(new ASN1Integer(dsaPubKey.getParams().getQ()));
vec.add(new ASN1Integer(dsaPubKey.getParams().getG()));
ASN1Sequence dssParams = new DERSequence(vec);
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, dssParams), new ASN1Integer(dsaPubKey.getY()));
return new MyKeypair(kp.getPrivate(), subjectPublicKeyInfo);
}
use of java.security.spec.DSAParameterSpec in project xipki by xipki.
the class CaClientExample method generateDsaKeypair.
protected static MyKeypair generateDsaKeypair() throws Exception {
// plen: 2048, qlen: 256
DSAParameterSpec spec = new DSAParameterSpec(P2048_Q256_P, P2048_Q256_Q, P2048_Q256_G);
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("DSA");
kpGen.initialize(spec);
KeyPair kp = kpGen.generateKeyPair();
DSAPublicKey dsaPubKey = (DSAPublicKey) kp.getPublic();
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new ASN1Integer(dsaPubKey.getParams().getP()));
vec.add(new ASN1Integer(dsaPubKey.getParams().getQ()));
vec.add(new ASN1Integer(dsaPubKey.getParams().getG()));
ASN1Sequence dssParams = new DERSequence(vec);
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, dssParams), new ASN1Integer(dsaPubKey.getY()));
return new MyKeypair(kp.getPrivate(), subjectPublicKeyInfo);
}
use of java.security.spec.DSAParameterSpec in project xipki by xipki.
the class DSAParameterCache method getNewDSAParameterSpec.
// CHECKSTYLE:SKIP
public static DSAParameterSpec getNewDSAParameterSpec(int plength, int qlength, SecureRandom random) {
final int certainty = 80;
SecureRandom tmpRandom = (random == null) ? new SecureRandom() : random;
DSAParametersGenerator paramGen = new DSAParametersGenerator(new SHA512Digest());
DSAParameterGenerationParameters genParams = new DSAParameterGenerationParameters(plength, qlength, certainty, tmpRandom);
paramGen.init(genParams);
DSAParameters dsaParams = paramGen.generateParameters();
return new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
}
use of java.security.spec.DSAParameterSpec in project xipki by xipki.
the class DSAParameterCache method addDSAParamSpec.
// CHECKSTYLE:SKIP
private static void addDSAParamSpec(int plen, int qlen, String strP, String strQ, String strG) {
DSAParameterSpec spec = new DSAParameterSpec(new BigInteger(strP, 16), new BigInteger(strQ, 16), new BigInteger(strG, 16));
cache.put(plen + "-" + qlen, spec);
}
use of java.security.spec.DSAParameterSpec in project Bytecoder by mirkosertic.
the class DSAKeyPairGenerator method initialize.
/**
* Initializes the DSA object using a DSA parameter object.
*
* @param params a fully initialized DSA parameter object.
*/
@Override
public void initialize(DSAParams params, SecureRandom random) throws InvalidParameterException {
if (params == null) {
throw new InvalidParameterException("Params must not be null");
}
DSAParameterSpec spec = new DSAParameterSpec(params.getP(), params.getQ(), params.getG());
initialize0(spec, random);
}
Aggregations