Java Code Examples for javax.crypto.spec.DHGenParameterSpec#getPrimeSize()

The following examples show how to use javax.crypto.spec.DHGenParameterSpec#getPrimeSize() . 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: JDKAlgorithmParameterGenerator.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 2
Source File: DHParameterGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 3
Source File: AlgorithmParameterGeneratorSpi.java    From ripple-lib-java with ISC License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 4
Source File: AlgorithmParameterGeneratorSpi.java    From ripple-lib-java with ISC License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 5
Source File: AlgorithmParameterGeneratorSpi.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 6
Source File: AlgorithmParameterGeneratorSpi.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 7
Source File: DHParameterGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 8
Source File: DHParameterGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 9
Source File: DHParameterGenerator.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
      SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 10
Source File: DHParameterGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 11
Source File: JDKAlgorithmParameterGenerator.java    From TorrentEngine with GNU General Public License v3.0 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
Example 12
Source File: DHParameterGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
      SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 13
Source File: DHParameterGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 14
Source File: DHParameterGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 15
Source File: DHParameterGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 16
Source File: DHParameterGenerator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 17
Source File: DHParameterGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
      SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 18
Source File: DHParameterGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
      SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
Example 19
Source File: DHParameterGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
Example 20
Source File: DHParameterGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
      SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}