use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.
protected AlgorithmParameters engineGenerateParameters() {
DSAParametersGenerator pGen;
if (strength <= 1024) {
pGen = new DSAParametersGenerator();
} else {
pGen = new DSAParametersGenerator(new SHA256Digest());
}
if (random == null) {
random = new SecureRandom();
}
if (strength == 1024) {
params = new DSAParameterGenerationParameters(1024, 160, 80, random);
pGen.init(params);
} else if (strength > 1024) {
params = new DSAParameterGenerationParameters(strength, 256, 80, random);
pGen.init(params);
} else {
pGen.init(strength, 20, random);
}
DSAParameters p = pGen.generateParameters();
AlgorithmParameters params;
try {
params = AlgorithmParameters.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME);
params.init(new DSAParameterSpec(p.getP(), p.getQ(), p.getG()));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return params;
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAPrivateKeyImpl method readObject.
private void readObject(java.io.ObjectInputStream in) throws NotActiveException, IOException, ClassNotFoundException {
in.defaultReadObject();
params = new DSAParameterSpec(p, q, g);
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class KeyAgreementTest method testInit02.
/**
* Test for the methods
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* Assertion: throws AlgorithmParameterException when params are
* inappropriate
*/
public void testInit02() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
SecureRandom random = null;
DSAParameterSpec dsa = new DSAParameterSpec(new BigInteger("56"), new BigInteger("56"), new BigInteger("56"));
for (int i = 0; i < kAgs.length; i++) {
try {
kAgs[i].init(privKey, dsa);
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(privKey, dsa, new SecureRandom());
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(privKey, dsa, random);
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
}
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class Signature2Test method test_setParameterLjava_security_spec_AlgorithmParameterSpec.
/**
* java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)
*/
public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() throws Exception {
Signature sig = Signature.getInstance("DSA");
try {
DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
sig.setParameter(spec);
} catch (InvalidParameterException e) {
// Could be that it's an invalid param for the found algorithm
} catch (UnsupportedOperationException e) {
// Could be that the operation is not supported
}
}
use of java.security.spec.DSAParameterSpec in project XobotOS by xamarin.
the class JDKDSAPublicKey method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
this.y = (BigInteger) in.readObject();
this.dsaSpec = new DSAParameterSpec((BigInteger) in.readObject(), (BigInteger) in.readObject(), (BigInteger) in.readObject());
}
Aggregations