Search in sources :

Example 31 with DSAParameterSpec

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

Example 32 with DSAParameterSpec

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

Example 33 with DSAParameterSpec

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

Example 34 with DSAParameterSpec

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

Example 35 with DSAParameterSpec

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

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