java.security.spec.DSAParameterSpec Java Examples

The following examples show how to use java.security.spec.DSAParameterSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DSAParameters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #2
Source File: DSAPublicKey.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #3
Source File: DSAPrivateKey.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #4
Source File: DSAPublicKey.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #5
Source File: DSAPrivateKey.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #6
Source File: DSAPublicKey.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #7
Source File: DSAPublicKey.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #8
Source File: DSAPrivateKey.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #9
Source File: DSAKeyPairGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates a pair of keys usable by any JavaSecurity compliant
 * DSA implementation.
 */
public KeyPair generateKeyPair() {
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    DSAParameterSpec spec;
    try {
        if (forceNewParameters) {
            // generate new parameters each time
            spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random);
        } else {
            if (params == null) {
                params =
                    ParameterCache.getDSAParameterSpec(plen, qlen, random);
            }
            spec = params;
        }
    } catch (GeneralSecurityException e) {
        throw new ProviderException(e);
    }
    return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random);
}
 
Example #10
Source File: DSAParameters.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #11
Source File: KeyPairGeneratorSpi.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof DSAParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a DSAParameterSpec");
    }
    DSAParameterSpec dsaParams = (DSAParameterSpec)params;

    param = new DSAKeyGenerationParameters(random, new DSAParameters(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()));

    engine.init(param);
    initialised = true;
}
 
Example #12
Source File: TestAlgParameterGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkParamStrength(AlgorithmParameters param,
        DSAGenParameterSpec genParam)
        throws Exception {
    String algo = param.getAlgorithm();
    if (!algo.equalsIgnoreCase("DSA")) {
        throw new RuntimeException("Unexpected type of parameters: " + algo);
    }
    DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
    int valueL = spec.getP().bitLength();
    int strength = genParam.getPrimePLength();
    if (strength != valueL) {
        System.out.println("P: Expected " + strength + " but actual " + valueL);
        throw new RuntimeException("Wrong P strength");
    }
    int valueN = spec.getQ().bitLength();
    strength = genParam.getSubprimeQLength();
    if (strength != valueN) {
        System.out.println("Q: Expected " + strength + " but actual " + valueN);
        throw new RuntimeException("Wrong Q strength");
    }
}
 
Example #13
Source File: DSAPublicKey.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #14
Source File: DSAKeyPairGenerator.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the DSA key pair generator. If <code>genParams</code>
 * is false, a set of pre-computed parameters is used.
 */
@Override
public void initialize(int modlen, boolean genParams,
    SecureRandom random) throws InvalidParameterException {
    if (genParams) {
        super.init(modlen, random, true);
    } else {
        DSAParameterSpec cachedParams =
            ParameterCache.getCachedDSAParameterSpec(modlen,
                getDefDSASubprimeSize(modlen));
        if (cachedParams == null) {
            throw new InvalidParameterException
                ("No precomputed parameters for requested modulus" +
                 " size available");
        }
        super.init(cachedParams, random, false);
    }
}
 
Example #15
Source File: DSAParameters.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #16
Source File: DSAPublicKey.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #17
Source File: DSAParameters.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #18
Source File: DSAPublicKey.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #19
Source File: DSAPrivateKey.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #20
Source File: DSAPublicKey.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #21
Source File: JDKDSAPublicKey.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
JDKDSAPublicKey(
    SubjectPublicKeyInfo    info)
{

    ASN1Integer              derY;

    try
    {
        derY = (ASN1Integer)info.parsePublicKey();
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in DSA public key");
    }

    this.y = derY.getValue();

    if (isNotNull(info.getAlgorithm().getParameters()))
    {
        DSAParameter params = DSAParameter.getInstance(info.getAlgorithm().getParameters());
        
        this.dsaSpec = new DSAParameterSpec(params.getP(), params.getQ(), params.getG());
    }
}
 
Example #22
Source File: DSAPrivateKey.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #23
Source File: KeyPairGeneratorSpi.java    From ripple-lib-java with ISC License 6 votes vote down vote up
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof DSAParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a DSAParameterSpec");
    }
    DSAParameterSpec dsaParams = (DSAParameterSpec)params;

    param = new DSAKeyGenerationParameters(random, new DSAParameters(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()));

    engine.init(param);
    initialised = true;
}
 
Example #24
Source File: DSAPrivateKey.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #25
Source File: DSAKeyPairGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initializes the DSA key pair generator. If <code>genParams</code>
 * is false, a set of pre-computed parameters is used.
 */
@Override
public void initialize(int modlen, boolean genParams,
    SecureRandom random) throws InvalidParameterException {
    if (genParams) {
        super.init(modlen, random, true);
    } else {
        DSAParameterSpec cachedParams =
            ParameterCache.getCachedDSAParameterSpec(modlen,
                getDefDSASubprimeSize(modlen));
        if (cachedParams == null) {
            throw new InvalidParameterException
                ("No precomputed parameters for requested modulus" +
                 " size available");
        }
        super.init(cachedParams, random, false);
    }
}
 
Example #26
Source File: DSAKeyPairGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initializes the DSA key pair generator. If <code>genParams</code>
 * is false, a set of pre-computed parameters is used.
 */
@Override
public void initialize(int modlen, boolean genParams,
    SecureRandom random) throws InvalidParameterException {
    if (genParams) {
        super.init(modlen, random, true);
    } else {
        DSAParameterSpec cachedParams =
            ParameterCache.getCachedDSAParameterSpec(modlen,
                getDefDSASubprimeSize(modlen));
        if (cachedParams == null) {
            throw new InvalidParameterException
                ("No precomputed parameters for requested modulus" +
                 " size available");
        }
        super.init(cachedParams, random, false);
    }
}
 
Example #27
Source File: DSAPrivateKey.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #28
Source File: DSAPublicKey.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
Example #29
Source File: DSAParameters.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException
{
        try {
            Class<?> dsaParamSpec = Class.forName
                ("java.security.spec.DSAParameterSpec");
            if (dsaParamSpec.isAssignableFrom(paramSpec)) {
                return paramSpec.cast(
                        new DSAParameterSpec(this.p, this.q, this.g));
            } else {
                throw new InvalidParameterSpecException
                    ("Inappropriate parameter Specification");
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidParameterSpecException
                ("Unsupported parameter specification: " + e.getMessage());
        }
}
 
Example #30
Source File: DSAPublicKey.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}