Search in sources :

Example 26 with DSAParameterSpec

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;
}
Also used : DSAParametersGenerator(org.bouncycastle.crypto.generators.DSAParametersGenerator) DSAParameterSpec(java.security.spec.DSAParameterSpec) SHA256Digest(org.bouncycastle.crypto.digests.SHA256Digest) DSAParameterGenerationParameters(org.bouncycastle.crypto.params.DSAParameterGenerationParameters) SecureRandom(java.security.SecureRandom) DSAParameters(org.bouncycastle.crypto.params.DSAParameters) InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 27 with DSAParameterSpec

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

Example 28 with DSAParameterSpec

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) {
        }
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) KeyAgreement(javax.crypto.KeyAgreement) InvalidKeyException(java.security.InvalidKeyException)

Example 29 with DSAParameterSpec

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

Example 30 with DSAParameterSpec

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

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