use of java.security.spec.DSAParameterSpec in project XobotOS by xamarin.
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 XobotOS by xamarin.
the class DSAPublicKeyImpl 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 KeyPairGeneratorTest method testDSAGeneratorWithParams.
public void testDSAGeneratorWithParams() throws Exception {
final DSAParameterSpec dsaSpec = new DSAParameterSpec(DSA_P, DSA_Q, DSA_G);
boolean failure = false;
final Provider[] providers = Security.getProviders();
for (final Provider p : providers) {
Service s = p.getService("KeyPairGenerator", "DSA");
if (s == null) {
continue;
}
final KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA", p);
kpg.initialize(dsaSpec);
KeyPair pair = kpg.generateKeyPair();
DSAPrivateKey privKey = (DSAPrivateKey) pair.getPrivate();
DSAPublicKey pubKey = (DSAPublicKey) pair.getPublic();
DSAParams actualParams = privKey.getParams();
assertNotNull("DSA params should not be null", actualParams);
assertEquals("DSA P should be the same as supplied with provider " + p.getName(), DSA_P, actualParams.getP());
assertEquals("DSA Q should be the same as supplied with provider " + p.getName(), DSA_Q, actualParams.getQ());
assertEquals("DSA G should be the same as supplied with provider " + p.getName(), DSA_G, actualParams.getG());
actualParams = pubKey.getParams();
assertNotNull("DSA params should not be null", actualParams);
assertEquals("DSA P should be the same as supplied with provider " + p.getName(), DSA_P, actualParams.getP());
assertEquals("DSA Q should be the same as supplied with provider " + p.getName(), DSA_Q, actualParams.getQ());
assertEquals("DSA G should be the same as supplied with provider " + p.getName(), DSA_G, actualParams.getG());
}
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAKeyPairGeneratorTest method test_DSAKeyPairGenerator01.
/**
* java.security.interfaces.DSAKeyPairGenerator
* #initialize(DSAParams params, SecureRandom random)
*/
public void test_DSAKeyPairGenerator01() {
DSAParams dsaParams = new DSAParameterSpec(p, q, g);
SecureRandom random = null;
MyDSA dsa = new MyDSA(dsaParams);
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch (Exception e) {
fail("Unexpected exception for SecureRandom: " + e);
}
try {
dsa.initialize(dsaParams, random);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
dsa.initialize(dsaParams, null);
fail("InvalidParameterException was not thrown");
} catch (InvalidParameterException ipe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of InvalidParameterException");
}
try {
dsa.initialize(null, random);
fail("InvalidParameterException was not thrown");
} catch (InvalidParameterException ipe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of InvalidParameterException");
}
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAKeyPairGeneratorTest method test_DSAKeyPairGenerator02.
/**
* java.security.interfaces.DSAKeyPairGenerator
* #initialize(int modlen, boolean genParams, SecureRandom randomm)
*/
public void test_DSAKeyPairGenerator02() {
int[] invalidLen = { -1, 0, 511, 513, 650, 1023, 1025 };
DSAParams dsaParams = new DSAParameterSpec(p, q, g);
SecureRandom random = null;
MyDSA dsa = new MyDSA(null);
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch (Exception e) {
fail("Unexpected exception for SecureRandom: " + e);
}
//exception case
try {
dsa.initialize(520, false, random);
fail("InvalidParameterException was not thrown");
} catch (InvalidParameterException ipe) {
String str = ipe.getMessage();
if (!str.equals("there are not precomputed parameters")) {
fail("Incorrect exception's message: " + str);
}
} catch (Exception e) {
fail(e + " was thrown instead of InvalidParameterException");
}
//exception case
for (int i = 0; i < invalidLen.length; i++) {
try {
dsa.initialize(invalidLen[i], true, random);
fail("InvalidParameterException was not thrown");
} catch (InvalidParameterException ipe) {
String str = ipe.getMessage();
if (!str.equals("Incorrect modlen")) {
fail("Incorrect exception's message: " + str);
}
} catch (Exception e) {
fail(e + " was thrown instead of InvalidParameterException");
}
}
//positive case
dsa = new MyDSA(dsaParams);
try {
dsa.initialize(520, true, random);
} catch (Exception e) {
fail(e + " was thrown for subcase 1");
}
//positive case
try {
dsa.initialize(520, false, random);
} catch (Exception e) {
fail(e + " was thrown for subcase 1");
}
}
Aggregations