Java Code Examples for java.security.spec.RSAKeyGenParameterSpec#getPublicExponent()

The following examples show how to use java.security.spec.RSAKeyGenParameterSpec#getPublicExponent() . 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: 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 RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
 
Example 2
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 RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
 
Example 3
Source File: RSAKeyPairGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 4
Source File: RSAKeyPairGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 5
Source File: RSAKeyPairGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 6
Source File: RSAKeyPairGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 7
Source File: RSAKeyPairGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 8
Source File: RSAKeyPairGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 9
Source File: RSAKeyPairGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 10
Source File: RSAKeyPairGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 11
Source File: RSAKeyPairGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 12
Source File: RSAKeyPairGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 13
Source File: RSAKeyPairGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}