Search in sources :

Example 6 with DSAParameterSpec

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());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParams(java.security.interfaces.DSAParams)

Example 7 with DSAParameterSpec

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());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) KeyPair(java.security.KeyPair) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator) DSAPublicKey(java.security.interfaces.DSAPublicKey)

Example 8 with DSAParameterSpec

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());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) BigInteger(java.math.BigInteger)

Example 9 with DSAParameterSpec

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());
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) BigInteger(java.math.BigInteger)

Example 10 with DSAParameterSpec

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
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) BigInteger(java.math.BigInteger) IOException(java.io.IOException) AlgorithmParameters(java.security.AlgorithmParameters)

Aggregations

DSAParameterSpec (java.security.spec.DSAParameterSpec)56 BigInteger (java.math.BigInteger)20 DSAParams (java.security.interfaces.DSAParams)16 KeyPairGenerator (java.security.KeyPairGenerator)12 SecureRandom (java.security.SecureRandom)10 AlgorithmParameters (java.security.AlgorithmParameters)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)6 DSAPublicKey (java.security.interfaces.DSAPublicKey)6 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)6 KeyPair (java.security.KeyPair)5 InvalidParameterException (java.security.InvalidParameterException)4 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)3 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)2 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)2