use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAParamsTest method test_getP.
/**
* java.security.interfaces.DSAParams
* #getP()
*/
public void test_getP() {
DSAParams params = new DSAParameterSpec(p, q, g);
assertEquals("Invalid P", p, params.getP());
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAPublicKeyTest method test_getY.
/**
* java.security.interfaces.DSAPublicKey
* #getY()
* test covers following use cases
* Case 1: check with predefined p, q, g, x
* Case 2: check with random p, q, g, x. It takes some time (up to
* minute)
*/
public void test_getY() throws Exception {
KeyPairGenerator keyGen = null;
KeyPair keys = null;
DSAPrivateKey priv = null;
DSAPublicKey publ = null;
// Case 1: check with predefined p, q, g, x
keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(new DSAParameterSpec(Util.P, Util.Q, Util.G), new SecureRandom(new MySecureRandomSpi(), null) {
});
keys = keyGen.generateKeyPair();
priv = (DSAPrivateKey) keys.getPrivate();
publ = (DSAPublicKey) keys.getPublic();
assertNotNull("Invalid Y value", publ.getY());
// Case 2: check with random p, q, g, x. It takes some time (up to
// minute)
keyGen = KeyPairGenerator.getInstance("DSA");
keys = keyGen.generateKeyPair();
priv = (DSAPrivateKey) keys.getPrivate();
publ = (DSAPublicKey) keys.getPublic();
assertNotNull("Invalid Y value", publ.getY());
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAParameterSpecTest method testGetP.
/**
* getP() test
*/
public final void testGetP() {
DSAParameterSpec dps = new DSAParameterSpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"));
assertEquals(1, dps.getP().intValue());
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class DSAParameterSpecTest method testGetQ.
/**
* getQ() test
*/
public final void testGetQ() {
DSAParameterSpec dps = new DSAParameterSpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"));
assertEquals(2, dps.getQ().intValue());
}
use of java.security.spec.DSAParameterSpec in project robovm by robovm.
the class AlgorithmParametersTest method testDSAProvider.
/**
* Tests DSA AlgorithmParameters provider
*/
public void testDSAProvider() throws Exception {
AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
assertEquals("Algorithm", "DSA", params.getAlgorithm());
// init(AlgorithmParameterSpec)
BigInteger p = BigInteger.ONE;
BigInteger q = BigInteger.TEN;
BigInteger g = BigInteger.ZERO;
params.init(new DSAParameterSpec(p, q, g));
// getEncoded() and getEncoded(String) (TODO verify returned encoding)
byte[] enc = params.getEncoded();
assertNotNull(enc);
assertNotNull(params.getEncoded("ASN.1"));
// TODO assertNotNull(params.getEncoded(null)); // HARMONY-2680
// getParameterSpec(Class)
DSAParameterSpec spec = params.getParameterSpec(DSAParameterSpec.class);
assertEquals("p is wrong ", p, spec.getP());
assertEquals("q is wrong ", q, spec.getQ());
assertEquals("g is wrong ", g, spec.getG());
// init(byte[])
params = AlgorithmParameters.getInstance("DSA");
params.init(enc);
assertTrue("param encoded is different", Arrays.equals(enc, params.getEncoded()));
// init(byte[], String)
params = AlgorithmParameters.getInstance("DSA");
params.init(enc, "ASN.1");
assertTrue("param encoded is different", Arrays.equals(enc, params.getEncoded()));
params = AlgorithmParameters.getInstance("DSA");
try {
params.init(enc, "DOUGLASMAWSON");
fail("unsupported format should have raised IOException");
} catch (IOException e) {
// expected
}
}
Aggregations